Open ts-project opened 9 months ago
interesting topic, here is my quick reply:
Again, don't believe this approach is right, but just wanted to share what I've tried.
=> yes you are doing right
When I include zeros as the initial balance before a first trade, I get an error that says
=> yes pls drop NaN in the returns
ValueError Traceback (most recent call last) in 200 201 --> 202 run_strategies(0.5,0.75,9) 203 204
in run_strategies(ratio, ratio_2, min_pnldd) 140 # Optimize for maximal Sharpe ratio 141 ef = EfficientFrontier(mu, S) --> 142 raw_weights = ef.max_sharpe() 143 cleaned_weights = ef.clean_weights() 144 # ef.save_weights_to_file("weights.csv") # saves to file
=> I guess your covariance matrix S
is not valid, could you share how you compute the mu
and S
Rather than use PyPortfolioOpt to weight or balance a set of stocks or assets, I am trying to use it to weight or balance a set of algo futures trading strategies. Trying to achieve what the README describes as "an algorithmic trader who has a basket of strategies".
I have dataframes of the trades taken by each strategy for a single futures contract with each trade date, the profit/loss in dollars, and a trade-by-trade cumulative balance per strategy, among other data points like drawdown etc. If needed, I also certainly have entry and exit prices for each futures trade (but obviously this would require each contract's point values to calculate the actual PnL).
What I don't quite understand is how to use PyPortfolioOpt when using this sort of trade by trade data for a set of strategies, rather than what the examples describe, which appears to be more of a weighted buy and hold approach and using the adjusted close prices for a set of assets over a period of time.
Thanks for any input and feedback on how to optimize a basket of algo strategies.
While I don't believe what I describe below is probably close to the right approach, let me also share what I have tried.
I have tried building a dataframe with the various strategies as columns and with each of their daily cumulative balances as rows.
If a strategy didn't take a trade on a given day, then the "adjusted close" value or balance of that strategy would remain the previous day's balance.
When I chop the dataframe to only include rows that have no initial balance (or zero values) for a strategy's initial balance and each strategy has already experienced a first trade, I don't get any errors, but all of my returned raw weights are 'nan'. This is also true if I don't chop the dataframes and include 'nan' as an initial balance rather than 0.
Again, don't believe this approach is right, but just wanted to share what I've tried.
When I include zeros as the initial balance before a first trade, I get an error that says:
Followed by: