Giter VIP home page Giter VIP logo

Comments (1)

jinyiabc avatar jinyiabc commented on May 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.