Comments (1)
import yfinance as yf
import matplotlib.pyplot as plt
Import MlFinLab tools
from mlfinlab.labeling.trend_scanning import trend_scanning_labels
Loading EEM ETF daily close prices during the financial crises
eem_close = yf.download(
tickers="EEM", start="2008-07-01", end="2009-07-01", interval="1d"
)["Adj Close"]
Getting indexes that we want to label
t_events = eem_close.index
tr_scan_labels = trend_scanning_labels(
eem_close, t_events, observation_window=20, look_forward=False, min_sample_length=5
)
tr_scan_labels.dropna(subset=["bin"])
''''''''''''''
t1 t_value ret bin
Date
2008-07-29 2008-07-15 -1.001403 -0.043901 -1.0
2008-07-30 2008-07-08 1.784318 -0.007165 1.0
2008-07-31 2008-07-10 1.106360 0.013099 1.0
2008-08-01 2008-07-22 -1.362230 0.032972 -1.0
2008-08-04 2008-07-11 -8.658784 0.045189 -1.0
... ... ... ... ...
2009-06-24 2009-06-19 -6.849154 0.008768 -1.0
2009-06-25 2009-06-23 -5.874661 -0.049767 -1.0
2009-06-26 2009-06-04 7.476431 0.029371 1.0
2009-06-29 2009-06-08 8.294161 0.008074 1.0
2009-06-30 2009-06-10 5.052513 0.033169 1.0
'''''''''''''
def tValLinR(close):
"""tValue from a linear trend via SNIPPET 5.1 T-VALUE OF A LINEAR TREND
Args:
close (Series): close prices to search through
Returns:
float: t-value
Example:
>>> lookforward = 5
>>> start = 0
>>> stop = stop + lookforward
>>> df1 = close.iloc[start:stop]
>>> tValLinR(df1.values)
"""
x = np.ones((close.shape[0], 2))
x[:, 1] = np.arange(close.shape[0])
ols = sm1.OLS(close, x).fit()
return ols.tvalues[1]
tValLinR(eem_close.loc['2008-07-16':'2008-07-29'])
'''''''''''''
-1.0014031858892483
'''''''''''''
from mlfinlab.
Related Issues (20)
- Installing mlfinlab on Python 3.7.9 HOT 2
- get_signal(prob, num_classes, pred=None) maybe wrong.
- get_time_bars returning unix timestamp in `date_time` column
- `num_backtest_paths` in `CombinatorialPurgedKFold` returns incorrect value HOT 1
- no module `regime_change` in mlfinlab 1.5.0
- `get_time_bars` returning incorrect unix timestamp
- Any idea of adding code of bull bear labeling? HOT 2
- Getting TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'Timedelta' form the get daily volatility function
- MultiAssetPurgedKFold and MultiAssetCombinatorialPurgedKFold are throwing TypeError: '>=' not supported between instances of 'tuple' and 'str'
- problems when using ml_cross_val_score HOT 1
- Project dependencies may have API risk issues
- Unable to do a fresh install of mlfinlab HOT 1
- is the many function still not implemented? HOT 1
- CPCV does not work as intended and returns the exact same path.
- Triple barrier events code returning IndexError 0 out of bounds HOT 2
- The examples of filter and meta-labeling are cheating HOT 3
- The code of ETF Trick is empty
- Noise reduction features leakage/inconsistency
- How to use the etf trick with volume or dollar bars with different time indices for each bar?
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.
from mlfinlab.