AI-Powered Development

1

Download Documentation

Download the LLM Optimized TFire documentation file.

2

Attach Documentation

Create a project in Claude with attached documentation.

3

Ask Questions

Ask the LLM about any aspect of TFire - from basic concepts to complex strategies.

4

Get Detailed Answers

Receive clear explanations and working code.

Setting Up a Simple Case

U
How can I analyze returns for days when price is above vs below a 200-day moving average?
AI
Here's how to compare returns based on MA position:
# Setup collection with SMA spec = Specification(["SPY"], Date(2020,1,1), Date(2024,1,1)) collection = setup_collection(spec) collection.layer_settings_pending[LayerSMA][:win_sizes] = [200] collection_sma = add_layer(collection, LayerSMA) # Create filtering function function above_ma(args) price = args[1] ma = args[2] return price[end] > ma[end] end # Get data views dv_price = DVPriceSeries(collection_sma, :close_price) dv_ma = DVLayerDictKey(collection_sma, :ma_values, 200) # Filter and analyze collection_above = filter_collection(collection_sma, [dv_price, dv_ma], above_ma) mean_return_above = mean_compound_return(collection_above, 20) mean_return_all = mean_compound_return(collection_sma, 20) # Plot difference diff_return = mean_return_above .- mean_return_all plot_line(diff_return, name="Above MA - All Returns")

Strategy Design

U
I want to build a strategy that trades based on relative strength between sectors. How should I structure this in TFire?
AI
Here's a suggested approach using TFire's framework:
# 1. Set up collections for different sectors function setup_sector_collection(tickers, name) spec = Specification(tickers, Date(2023,1,1), Date(2024,1,1)) collection = setup_collection(spec) # Add momentum calculation layer collection.layer_settings_pending[LayerEMA][:win_sizes] = [20, 60] collection_momentum = add_layer(collection, LayerEMA) return collection_momentum end # Example sector setup tech_tickers = ["AAPL", "MSFT", "GOOGL"] finance_tickers = ["JPM", "BAC", "GS"] tech_collection = setup_sector_collection(tech_tickers, "Tech") finance_collection = setup_sector_collection(finance_tickers, "Finance") # 2. Create relative strength comparison function relative_strength(args) sector_ma = args[1] benchmark_ma = args[2] return sector_ma[end]/sector_ma[end-20] > benchmark_ma[end]/benchmark_ma[end-20] end # 3. Create scoring based on relative performance dv_tech = DVLayerDictKey(tech_collection, :ma_values, 20) dv_finance = DVLayerDictKey(finance_collection, :ma_values, 20) # Generate buy signals for outperforming sector tech_scores = BuyScores(tech_collection, [dv_tech, dv_finance], relative_strength)

Error Troubleshooting

U
I'm getting an error 'DataFields not available from Yahoo Finance' when trying to fetch data. What am I doing wrong?
AI
This error occurs when requesting fields that aren't available from Yahoo Finance. Here's the correct way to set up your specification:
# Yahoo Finance only supports these fields by default spec = Specification(["AAPL", "MSFT"], Date(2023,1,1), Date(2024,1,1) ) # If you need specific fields, explicitly specify supported ones spec.data_fields = DataFields(Set([ :close, :adj_close, :open, :low, :high, :volume ]))collection = setup_collection(spec)

Adding Custom Layers

U
How can I create a custom layer for calculating ATR (Average True Range)
AI
Here's a complete implementation of an ATR layer following TFire's layer structure:
# 1. Define the layer struct # 1. Define the layer struct mutable struct LayerATR <: AssetLayer atr_values::Vector{Float64} tr_values::Vector{Float64} end # 2. Define the repainting trait (ATR is non-repainting) function LayerRepaintingTrait(::Type{<:LayerATR}) return NonRepainting() end # 3. Set default parameters function default_parameters(::Type{LayerATR}) return Parameters(LayerATR, Dict{Symbol, Any}( :period => 14, :price_high => :high, :price_low => :low, :price_close => :close )) end # 4. Implement the layer logic function _produce_layer(::Type{LayerATR}, asset::Asset, settings::Settings, settings_used::Settings, collection_settings::SettingsCollection; common_input=nothing) # Get parameters period = get_parameter(settings, LayerATR, :period) high_field = get_parameter(settings, LayerATR, :price_high) low_field = get_parameter(settings, LayerATR, :price_low) close_field = get_parameter(settings, LayerATR, :price_close) ...