Skip to content

Commit

Permalink
Merge pull request #126 from sheriff4000/FALM
Browse files Browse the repository at this point in the history
import dotmaps
  • Loading branch information
sheriff4000 authored Jun 6, 2024
2 parents 3c074be + 05d0ec7 commit 060e715
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Backtest/strategies/FALM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using ...Structures: ContextTypeA
using DataFrames: DataFrame
using DirectSearch
using Suppressor
using DotMaps

"""
initialize!
Expand All @@ -34,7 +35,7 @@ function falm_initialize!(
assetIDs::Union{Vector{String}}=nothing, # Associated AssetIDs for the tickers
transactionCost::Real=0.02, # Transaction cost
currency::String="FEX/USD", # Currency to use
forecastFun::Forecaster=LinearForecaster(1, 0), # Forecasting function
forecaster::Forecaster=LinearForecaster(1, 0), # Forecasting function
httype::Int=1, # 1: Weighted Average holding time, 2: Minimum holding time
min_alloc_threshold::Float64=0.7,
min_returns_threshold::Float64=0.0002,
Expand All @@ -50,7 +51,7 @@ function falm_initialize!(
context.extra.currentValue = DataFrame()
context.extra.currency_symbol = currency
context.extra.assetIDs = assetIDs
context.extra.forecastFun = forecastFun
context.extra.forecaster = forecaster
context.extra.httype = httype
context.extra.min_alloc_threshold = min_alloc_threshold
context.extra.min_returns_threshold = min_returns_threshold
Expand Down Expand Up @@ -124,7 +125,7 @@ function compute_portfolio!(context::ContextTypeA; data=DataFrame())
prices = data[data.symbol .== t, :close]
# CUSTOM FORECAST ##
forecast = applyForecast(
context.extra.forecastFun, prices; F=context.extra.lookahead
context.extra.forecaster, prices; F=context.extra.lookahead
)
relative_returns = log.(forecast ./ prices[end])
relative_returns = [relative_returns[i] / i for i in 1:(context.extra.lookahead)]
Expand Down

0 comments on commit 060e715

Please sign in to comment.