Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in PlotToolPro #94

Open
zoeyzhougs opened this issue Feb 24, 2020 · 7 comments
Open

Regression in PlotToolPro #94

zoeyzhougs opened this issue Feb 24, 2020 · 7 comments

Comments

@zoeyzhougs
Copy link
Collaborator

zoeyzhougs commented Feb 24, 2020

Describe the problem.
Regression should be available in PlotToolPro.

Describe the solution you'd like
Add a class in gs-quant (constructor in PlotToolPro) for the model fitting which has methods to get model parameters and perform prediction.

For example, linear regression should take the form LinearRegression(X, y, w) where X denotes explanatory variables [x1, x2, x3, ...], y is the dependent variable and w is the moving window. The class has methods:
coefficient(i) - the i-th coefficient
rsquare() - model R squared
tstat(i) - t-stat of the i-th coefficient
fitted_values() - fitted values
predict(X') where X' is the test set of explanatory variables - predicated values (Note: if multiple regression models have been fitted over the moving window, the most recent model will be used for prediction)

In PlotToolPro, users could fit a linear regression between changes of implied volatility of S&P 500 index and returns on the underlying by:

spx = returns(SPX.spot(), 1, simple)
spx_vol = diff(SPX.implied_volatility(1m, forward, 100), 1)
r = LinearRegression([spx], spx_vol, 60)
r.fitted_values()

Are you willing to contribute
Yes

@zoeyzhougs zoeyzhougs changed the title Regression Regression in PlotToolPro Feb 24, 2020
@francisg77
Copy link
Contributor

Looks good to me, should we do r_square and t_stat just to be consistent with other methods.

what does an example with predict look like?

@zoeyzhougs
Copy link
Collaborator Author

Agreed on the namings.
For now it's hard to use the predict function as we don't have functions to easily split data into train and test subsets. One example that needs improve:

spx = returns(SPX.spot(), simple)
spx_vol = diff(SPX.implied_volatility(1m, forward, 100), 1)
spx_train = interpolate(spx, [2020-02-01, 2020-02-02, 2020-02-03])
spx_vol_train = interpolate(spx_vol, [2020-02-01, 2020-02-02, 2020-02-03])
spx_test = interpolate(spx, [2020-02-04, 2020-02-05])
r = LinearRegression([spx_train], spx_vol_train)
r.predict(spx_test)

@zoeyzhougs
Copy link
Collaborator Author

renaming r_square to r_squared

@Atharva-Peshkar
Copy link

Agreed on the namings.
For now it's hard to use the predict function as we don't have functions to easily split data into train and test subsets. One example that needs improve:

spx = returns(SPX.spot(), simple)
spx_vol = diff(SPX.implied_volatility(1m, forward, 100), 1)
spx_train = interpolate(spx, [2020-02-01, 2020-02-02, 2020-02-03])
spx_vol_train = interpolate(spx_vol, [2020-02-01, 2020-02-02, 2020-02-03])
spx_test = interpolate(spx, [2020-02-04, 2020-02-05])
r = LinearRegression([spx_train], spx_vol_train)
r.predict(spx_test)

I'm a student and have been working in ML for a while now. I'm a new contributor here. We could use the train_test_split function from sklearn library for easily splitting the training and test datasets. It'll help with the predict function. I would've done it but am not able to find PlotToolPro.

@andrewphillipsn
Copy link
Contributor

@Atharva-Peshkar thanks for the input. we can run an example which is pure python, you don't need access to the PlotTool Pro application as the functions being discussed are exposed in the timeseries module in GS Quant. Give us a shout if you are keen to extend and we can give some guidance and add a tutorial

@Atharva-Peshkar
Copy link

@andyphillipsgs Yeah! sure I'd be glad to contribute.

@Atharva-Peshkar thanks for the input. we can run an example which is pure python, you don't need access to the PlotTool Pro application as the functions being discussed are exposed in the timeseries module in GS Quant. Give us a shout if you are keen to extend and we can give some guidance and add a tutorial

@sirinath
Copy link

It might be an idea to open source plot tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants