algorithmic_trading_machine_learning's People
Forkers
syunar incogniro armstjc rakshan1996 ericleo8 ducthpoc praveen686 abhaysaxena1904 eclipse1228 mazaved jugeshprajapati tmpmosisili stonedrop slowdive42 dsalunga andrewhall1124 danielhiversen jay75chauhan sanjay001-eng robsoik angelo864 boobogo vmanjunathan erickvivas415 cld4h samirsl drkorossy gsebasscamarillo annvay assetoverflow ybkangster billythekidz gustavo9815 rorozoa7 seeincodes yuenshingyan aikilie pravirpolly impesud arendonb76 pkdefi malemaner mikouse ralphbrodriguez hamudileon nithamitabh shreyanshshukla-git kurucan chessonmoon kpunith8 tenkee ahamedalishaik muharremokutan kumarbirendra lakshayyyyy612 avig00 cd-github-g baridhi deepmanalg sigmalgebra darrelldunn707 mobley-trent joedev2 apurvapm carloscruz1 kaiserphemi iambenn soumo0 dhee2211 adepentane codebadolo jaab code4aravsha aidanaxylcloud huannvstj henrique-bardella xyztlp mliserb stokoloko89 mab4124 tunglinwood jdaiming m-ozbilgin anhtuan23 joe-nano dravidshankar jujuaria khushisachdev jsonpythonwill safwane-b trangdtk-vnu d-ashby dreganism robertoreverendo pandaskiing smaiti1 charliemei1112 kris12358 tnewaz84 willsghalgorithmic_trading_machine_learning's Issues
Macd bug
I keep getting error from macd:
def compute_macd(close):
macd = pandas_ta.macd(close=close, length=20).iloc[:,0]
return macd.sub(macd.mean()).div(macd.std())
df['macd'] = df.groupby(level=1, group_keys=False)['adj close'].apply(compute_macd)
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'
result = self._python_apply_general(f, self._selected_obj)
values, mutated = self._grouper.apply_groupwise(f, data, self.axis)
res = f(group)
return op(a, b)
what is the solution
"None of ['index'] are in the columns"
### I keep getting the following:
Max Sharpe Optimization failed for 2018-05-01, Continuing with Equal-Weights
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
Max Sharpe Optimization failed for 2019-01-01, Continuing with Equal-Weights
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
Max Sharpe Optimization failed for 2020-03-01, Continuing with Equal-Weights
"None of ['index'] are in the columns"
Max Sharpe Optimization failed for 2020-04-01, Continuing with Equal-Weights
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
Max Sharpe Optimization failed for 2021-02-01, Continuing with Equal-Weights
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
Max Sharpe Optimization failed for 2021-10-01, Continuing with Equal-Weights
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
Max Sharpe Optimization failed for 2022-09-01, Continuing with Equal-Weights
"None of ['index'] are in the columns"
Max Sharpe Optimization failed for 2022-10-01, Continuing with Equal-Weights
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
Max Sharpe Optimization failed for 2023-11-01, Continuing with Equal-Weights
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
"None of ['index'] are in the columns"
### after this part:
returns_dataframe = np.log(new_df['Adj Close']).diff()
portfolio_df = pd.DataFrame()
for start_date in fixed_dates.keys():
try:
end_date = (pd.to_datetime(start_date)+pd.offsets.MonthEnd(0)).strftime('%Y-%m-%d')
cols = fixed_dates[start_date]
optimization_start_date = (pd.to_datetime(start_date)-pd.DateOffset(months=12)).strftime('%Y-%m-%d')
optimization_end_date = (pd.to_datetime(start_date)-pd.DateOffset(days=1)).strftime('%Y-%m-%d')
optimization_df = new_df[optimization_start_date:optimization_end_date]['Adj Close'][cols]
success = False
try:
weights = optimize_weights(prices=optimization_df,
lower_bound=round(1/(len(optimization_df.columns)*2),3))
weights = pd.DataFrame(weights, index=pd.Series(0))
success = True
except:
print(f'Max Sharpe Optimization failed for {start_date}, Continuing with Equal-Weights')
if success==False:
weights = pd.DataFrame([1/len(optimization_df.columns) for i in range(len(optimization_df.columns))],
index=optimization_df.columns.tolist(),
columns=pd.Series(0)).T
temp_df = returns_dataframe[start_date:end_date]
temp_df = temp_df.stack().to_frame('return').reset_index(level=0)\
.merge(weights.stack().to_frame('weight').reset_index(level=0, drop=True),
left_index=True,
right_index=True)\
.reset_index().set_index(['Date', 'index']).unstack().stack()
temp_df.index.names = ['date', 'ticker']
temp_df['weighted_return'] = temp_df['return']*temp_df['weight']
temp_df = temp_df.groupby(level=0)['weighted_return'].sum().to_frame('Strategy Return')
portfolio_df = pd.concat([portfolio_df, temp_df], axis=0)
except Exception as e:
print(e)
portfolio_df = portfolio_df.drop_duplicates()
portfolio_df
PyPortfolioOpt will not install on Mac. Python Version 3.12
I am unable to get PyPortfolioOpt to install on map. I have Xcode which means I have the required C++ but its still doesn't work.
the error is:
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for qdldl
Failed to build qdldl
ERROR: Could not build wheels for qdldl, which is required to install pyproject.toml-based projects
[end of output]
I the same error trying to install qdldl, cvxpy, and cvxopt.
KeyError: 'Adj Close'
Hi - When trying to create the optimization_df dataframe from new_df I getting a key error for 'Adj Close'. below is the error and the code that I am using. Has anyone else experienced this and have suggestions on how to resolve? Thanks!
Error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 3805, in get_loc
return self._engine.get_loc(casted_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc
File "index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 7081, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 7089, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Adj Close'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/filename", line 261, in
optimization_df = new_df[optimization_start_date:optimization_end_date]['Adj Close'][cols]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pandas/core/frame.py", line 4102, in getitem
indexer = self.columns.get_loc(key)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc
raise KeyError(key) from err
KeyError: 'Adj Close'
Code Snippet below:
stocks = data.index.get_level_values('ticker').unique().tolist()
new_df = yf.download(tickers=stocks,
start=data.index.get_level_values('date').unique()[0]-pd.DateOffset(months=12),
end=data.index.get_level_values('date').unique()[-1])
returns_dataframe = np.log(new_df['Adj Close']).diff()
portfolio_df = pd.DataFrame()
for start_date in fixed_dates.keys():
end_date = (pd.to_datetime(start_date)+pd.offsets.MonthEnd(0)).strftime('%Y-%m-%d')
cols =fixed_dates[start_date]
optimization_start_date = (pd.to_datetime(start_date)-pd.DateOffset(months=12)).strftime('%Y-%m-%d')
optimization_end_date = (pd.to_datetime(start_date)-pd.DateOffset(months=1)).strftime('%Y-%m-%d')
optimization_df = new_df[optimization_start_date:optimization_end_date]['Adj Close'][cols]
#i'm getting an error in this line above with 'Adj Close'
weights = optimize_weights(prices=optimization_df, lower_bound=round(1/(len(optimization_df.columns)*2),3))
weights = pd.DataFrame(weights, index=pd.Series(0))
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.