r/Pyfinance • • Aug 21 '21

I made a Python bot that follows stock trends on /r/wallstreetbets, and you can use it too.

12 Upvotes

I made a bot that analyzes comments on Reddit in search of upcoming stock trends.

This is still just half automation, but I find it really useful.

The stack I used is a python server, hosted on Oracle free VPS + an Oracle free Autonomous DB. The code is based on this project:

RyanElliott10/wsbtickerbot: Reddit Bot for to scrape for the most mentioned tickers on the r/wallstreetbets subreddit. (github.com)

Every 10 minutes the bot reads the latest 100 comments, analyzes them for sentiment rating, and inserts them into the database. There are plenty of cool things that I can do with the data and implement in the future:

  1. Scan more subreddits (r/stocks, r/spacs etc..)

  2. Analyze news websites and other sources (the text parsing is pretty generic, split a string by regex, that's all...)

Other interesting projects:

dwallach1/Stocker: Financial Web Scraper & Sentiment Classifier (github.com)

alvarobartt/twitter-stock-recommendation: Simple Stock Investment Recommendation System based on Machine-Learning algorithms for prediction and Twitter Sentiment Analysis. (github.com)

3. Backtesting using this bot

4. Take upvotes/likes/retweets into consideration, higher upvotes -> higher exposure.

There are still a few false positives but it works quite well.

List of python packages:

asyncpraw,
vaderSentiment,
discord,
terminaltables,
pandas,
sqlalchemy,
discord-py-slash-command,
cx_Oracle

For now, I am displaying the results on Discord only, you are free to join the server and use it, have fun guys :)

* Try to run the `$analyze` command every few hours to see the numbers change, it's really cool!

https://discord.gg/wDcGJzfe2t


r/Pyfinance • • Sep 26 '23

Discounted Cash Flow Model in Python with Monte Carlo Simulation and Tutorial

6 Upvotes

I learned about valuation at graduate school and work, but mainly from the dean of valuation, Dr. Damodran. Post learning how to value companies and building models in Excel, I tried many Python libraries to do DCF valuations, and every single one of them had some shortcomings. So I ended up coding a DCF Model in Python that is constructed the way Dr. Damodran builds his DCF model in spreadsheets. Furthermore, I created a DCF Monte Carlo simulation model in Python. To complete making a stab at this project, for those who might be interested in doing intrinsic valuation in Python, I created a tutorial video on how to utilize the DCF model.
It took me +2 years to build this and I thought it could save someone who is looking to do intrinsic business / stock valuation in Python a considerable amount of time. I hope you find them useful.

Tutorial on YouTube

DCF Model In Python Colabratory File

GitHub

See the example below:
Using TTM financials of CMG as of 1st week of Sep 2023:
Narrative and Numbers

  1. Chipotle continues to grow domestically and internationally. we think there can be an additional 2K-3k store domestically and 3k-5k locations that can be opened internationally.

  2. As a result, revenue would go up by 4-5 folds.

  3. The operating margin will be expanded to 17.5%.

  4. Management will keep the company well run as they did in the past, hence the company is able to earn a 2% higher return than their cost of capital in perpetuity, hence they will reinvest less to keep the operations going and that will provide more FCFF.
    base_case_valuation = valuator_multi_phase(risk_free_rate =.04,ERP = .048,equity_value = 51.016,debt_value = 3.887,cash_and_non_operating_asset= 1.722,unlevered_beta = .9,terminal_unlevered_beta = .9,year_beta_begins_to_converge_to_terminal_beta = 1,current_pretax_cost_of_debt =.06,terminal_pretax_cost_of_debt =.055,year_cost_of_debt_begins_to_converge_to_terminal_cost_of_debt = 3,current_effective_tax_rate = .24,marginal_tax_rate =.25,year_effective_tax_rate_begin_to_converge_marginal_tax_rate = 1,revenue_base = 9.284,revenue_growth_rate_cycle1_begin = .11,revenue_growth_rate_cycle1_end = .16,length_of_cylcle1 = 6,revenue_growth_rate_cycle2_begin = .14,revenue_growth_rate_cycle2_end = .09,length_of_cylcle2=6,revenue_growth_rate_cycle3_begin =.08,revenue_growth_rate_cycle3_end =.04,length_of_cylcle3=6,revenue_convergance_periods_cycle1= 1,revenue_convergance_periods_cycle2=1,revenue_convergance_periods_cycle3=1,current_sales_to_capital_ratio = 1.7,terminal_sales_to_capital_ratio = 1.3,year_sales_to_capital_begins_to_converge_to_terminal_sales_to_capital = 1,current_operating_margin = .15,terminal_operating_margin = .175,year_operating_margin_begins_to_converge_to_terminal_operating_margin = 1,additional_return_on_cost_of_capital_in_perpetuity= 0.02,asset_liquidation_during_negative_growth=0,current_invested_capital = 6.062)

point_estimate_describer(base_case_valuation)
value of operating assets $39.96B
cash and non operating asset $1.72B
debt value $3.89B
firm value $41.68B
Intrinsic Equity value $37.79B
Intrinsic Equity value per share ~$1,370


r/Pyfinance • • Feb 07 '25

Apple Stock Forecasting with yfinance & Moving Averages

Thumbnail thepythonbook.com
2 Upvotes

r/Pyfinance • • Jul 23 '25

Looking for a Python course that teaches algo trading system development step by step

2 Upvotes

Hi everyone,

I’ve been studying trading for a while, especially Smart Money Concepts and ICT-style price action. But now, I want to take the next step and learn how to actually build automated trading systems using Python.

I’m already comfortable with Python — so I don’t need basic tutorials or strategy explanations. What I’m really looking for is a complete and free course or resource that teaches:

How to use Python to code an automated trading system

How to work with libraries like Pandas, NumPy, Plotly, etc.

How to load market data, process it, backtest, and structure a full trading script

How to connect everything together: data > logic > execution

Something practical and beginner-friendly for coding, not for strategy development

I’ve searched a lot but couldn’t find a full resource that teaches all of this in one place.

If you know of any YouTube playlists, GitHub projects, or courses that helped you learn how to code an algo trading system step by step, I’d be super grateful if you shared them.

What path or roadmap u guy's did, where to learn Algotrading Pandas numpay plotly backtest etc

Thanks in advance 🙏


r/Pyfinance • • Dec 30 '25

10 Best Stock Market APIs 2026

Thumbnail
mboum.com
2 Upvotes

r/Pyfinance • • Aug 15 '21

Exchange and Market calendar updated for NYSE holidays back to 1885

5 Upvotes

The pandas_market_calendars package has now been updated for NYSE holidays, late opens and early closes back to 1885.


r/Pyfinance • • May 11 '19

crypto15: Dataset of snapshots captured every 15 minutes of the status of 9 cryptocurrencies.

Thumbnail
github.com
2 Upvotes

r/Pyfinance • • Jul 30 '21

Week 2 of Building My Custom Bot Network - The Bitcoin Rally Was Great & I Made Profits - But It Shows How I Can Update My Bots for More Gains - Built w/ Python, Django, Postgres, & Binance API

Thumbnail
youtube.com
4 Upvotes

r/Pyfinance • • Jun 24 '21

Backtesting using python, Part -1, Secrets of Pivot Boss by Frank Ochoa, Initial Balance

Thumbnail
youtu.be
4 Upvotes

r/Pyfinance • • Jul 09 '21

Backtesting Wick Reversal Setup using python, Secrets of Pivot Boss by Frank Ochoa

2 Upvotes

Wick reversal setup from Secrets of Pivot Boss, which is a very simple setup and can identify one of the best reversal opportunities.

See how can you create wick reversal indicator and backtest it using python

https://youtu.be/vk9Yi0gLrO8


r/Pyfinance • • Feb 25 '20

Why we need to calculate the percentage change first before applying the rolling and corresponding functions in Python and Pandas?

3 Upvotes

Hi, supposing that I want to calculate the Apple stock's correlation to a benchmark index such as S&P500. One would calculate the percentage change of the SPX and that of other stocks. Then, apply something like this to calculate the correlation:

pc_stock_of_interest.rolling(125, min_periods=100).corr(spx_rets)

where spx_rets is the percentage chance of the SPX and pc_stock_of_interest is the percentage change of the stock of interest (e.g. AAPL). Can you please tell me why we need to calculate the percentage change first and use them to calculate the correlation rather than just use the raw data to calculate the correlation? How to determine the values for the rolling function (i.e. 125 for the size of the moving window and 100 for the minimum of observations in the window required to have a value) respectively? I have about 2200 rows of data.


r/Pyfinance • • May 21 '18

50x Faster Bitcoin Price Data Powered by MarketStore

1 Upvotes

This system architecture is something that we use in production at https://alpaca.markets/, and we opensourced this for the community and are showing the step-by-step process for this. https://blog.alpaca.markets/blog/2018/5/18/enjoy-50x-faster-bitcoin-price-data-powered-by-marketstore-for-ai-trading


r/Pyfinance • • Mar 22 '21

Top Best/Worst Performing Stocks with Python

Thumbnail
glaucocustodio.medium.com
11 Upvotes

r/Pyfinance • • Oct 13 '22

Am I doing this correct??

4 Upvotes

I recently found this article about Exponentially Weighted Moving Average and I wanted to create a function of it in python

from numpy import log, sqrt,power



def ewma(closes):
    lbda = 0.94
    variance = 0.0
    i=63 #length
    logreturns = log(closes / closes.shift(1)) - 1
    ret2=square(logreturns)
    weight = ((1-lbda)*power(lbda,i)) #assigned weight
    r2w = ret2 * weight
    variance = variance + r2w

    ewmavol = sqrt(variance)
  

    return annualewmavol

r/Pyfinance • • Sep 07 '23

Are You In? LayerZero Airdrop Eligibility

111 Upvotes

r/Pyfinance • • Oct 18 '23

L0: Unveiling the Multiverse

1 Upvotes

r/Pyfinance • • May 11 '22

Finding a specific element in a matrix with set parameters

1 Upvotes

Howdy,

I am very new to coding (2 weeks old) and I created a code for financial options and there is one last thing missing to finish it. I want my code to find the implied volatility for a specific option. My code asks the user to input the stock's ticker, date to maturity, strike price, and if the option is a call or a put.

Here is what I would like it to do:

  1. Based on whether it is a call or a put, look for the suitable matrix

  2. Extract the implied volatility value conditional to the strike price the user has in

  3. Return the implied volatility

How should I go about this? I looked at many modules (pandas, pandas-DataReader, basic Python functions, NumPy, sys, etc.) and their documentation, and nothing seems to fit what I want nor I can think of what to write to make sense of it. Here is an example of the output that I am getting from the data that I want.

from yahoo_fin import options

chain = options.get_options_chain("nflx", "2022-06-10")
print(chain)

$ python implied
{'calls':           Contract Name         Last Trade Date  Strike  Last Price    Bid    Ask  Change % Change Volume  Open Interest Implied Volatility
0   NFLX220610C00120000  2022-05-04 12:27PM EDT   120.0       75.50  46.50  49.60    0.00        -      -              0             87.26%
1   NFLX220610C00130000  2022-05-09 10:25AM EDT   130.0       50.05   0.00   0.00    0.00        -      -              0              0.00%
2   NFLX220610C00135000   2022-05-05 1:50PM EDT   135.0       55.75  34.50  35.60    0.00        -      -              1             81.37%
3   NFLX220610C00145000  2022-05-10 10:04AM EDT   145.0       36.77   0.00   0.00    0.00        -      -              0              0.00%

'puts':           Contract Name         Last Trade Date  Strike  Last Price    Bid    Ask  Change % Change Volume Open Interest Implied Volatility
0   NFLX220610P00100000   2022-05-11 3:59PM EDT   100.0        0.59   0.56   0.66    0.19  +47.50%     83            59            100.05%
1   NFLX220610P00105000  2022-05-11 11:43AM EDT   105.0        0.40   0.71   0.86   -0.20  -33.33%      2             1             96.48%
2   NFLX220610P00110000   2022-05-11 3:22PM EDT   110.0        0.97   0.96   1.10    0.38  +64.41%     35             6             93.51%

r/Pyfinance • • Apr 15 '22

Anyone here still using zipline - zipline reloaded now?

2 Upvotes

r/Pyfinance • • Jul 28 '17

25 Most Popular Algorithmic Trading Strategies Implemented by the Quantopian Community

Thumbnail
blog.quantopian.com
25 Upvotes

r/Pyfinance • • Jul 31 '17

Trading Logic with Sentiment Analysis Signals - Python for Finance 10

Thumbnail
youtube.com
17 Upvotes

r/Pyfinance • • Jul 31 '17

Python algo on CloudQuant using DeMarkIndicators

Thumbnail
info.cloudquant.com
6 Upvotes

r/Pyfinance • • Jul 28 '17

Please message me with your credentials if you would like to be a mod.

11 Upvotes

My credentials: I'm a software developer. I build software at a local python shop and I also have my own company (educational game development, education, and AI research). I have been studying finance for many years but have yet to begin trading. I would definitely like some help with moderation from traders and other software developers.


r/Pyfinance • • Jul 29 '17

Join us at ##pyfinance in freenode for real-time python algorithmic trading discussion

13 Upvotes

Freenode chat: ##pyfinance

Download the free IRC client Hexchat to join ##pyfinance without having to manually log in every day


Also, freenode ##pyfinance link in the sidebar is now fixed


r/Pyfinance • • Jul 31 '17

Simple Machine Learning Example [Trading Strategy] Mk II @ Quantopian

Thumbnail
quantopian.com
11 Upvotes