GithubHelp home page GithubHelp logo

shashankvemuri / finance Goto Github PK

View Code? Open in Web Editor NEW
1.8K 1.8K 0.0 93.11 MB

150+ quantitative finance Python programs to help you gather, manipulate, and analyze stock market data

License: MIT License

Python 100.00%
algorithmic-trading data-science finance machine-learning pandas python quantitative-finance stock stock-market stocks technical-indicators trading-strategies

finance's Introduction

Hi there 👋 I am Shashank Vemuri
Shashank @LinkedIn Shashank @Mail Shashank @Medium

Thanks for checking out my profile! If you have any questions, want to chat, or just want to get to know me better, don't hesitate to reach out to me using my contact info above.





Projects I'm Currently Working On!

ReadMe Card


visitors

finance's People

Contributors

dependabot[bot] avatar royopa avatar shashankvemuri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

finance's Issues

Questions regarding raw implementations

There are other libraries with libraries that makes calculation easier, and it is understood that this is merely for education purposes only (?)

  1. Why are Tensorflow and other neural network libraries used at times? https://github.com/google/tf-quant-finance
  2. What are the pros and cons of using established quant libraries? Like:
  1. How is this different from "backtesting"?

find_stocks/stock_news_sentiment.py - Not working out of the box

Greetings,
in my case the code does not work out of the box.

  1. HTTP 403 when reaching Finviz: changed the user agent and solved.
  2. NLTK missing dictionary errror: added the download in the code
  3. Error on the date because it was "Today" and not in a date format: added the code to managed it.

Below the code that worked for me:

# Import necessary libraries
import pandas as pd
from bs4 import BeautifulSoup
from urllib.request import urlopen, Request
from nltk.sentiment.vader import SentimentIntensityAnalyzer
import nltk
from datetime import datetime 

nltk.download('vader_lexicon')

# Define parameters
num_headlines = 3  # the number of article headlines displayed per ticker
tickers = ['AAPL', 'TSLA', 'AMZN']  # list of tickers to analyze

# Get data from finviz website
finviz_url = 'https://finviz.com/quote.ashx?t='
news_tables = {}

for ticker in tickers:
    url = finviz_url + ticker
    req = Request(url=url, headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'})
    resp = urlopen(req)
    html = BeautifulSoup(resp, features="lxml")
    news_table = html.find(id='news-table')
    news_tables[ticker] = news_table

# Display recent news headlines for each ticker
try:
    for ticker in tickers:
        df = news_tables[ticker]
        df_tr = df.findAll('tr')

        print('\n')
        print('Recent News Headlines for {}: '.format(ticker))

        for i, table_row in enumerate(df_tr):
            a_text = table_row.a.text
            td_text = table_row.td.text.strip()
            print(a_text, '(', td_text, ')')
            if i == num_headlines - 1:
                break
except KeyError:
    pass

# Extract and parse news data
parsed_news = []
for ticker, news_table in news_tables.items():
    for row in news_table.findAll('tr'):
        text = row.a.get_text()
        date_scrape = row.td.text.split()

        if len(date_scrape) == 1:
            time = date_scrape[0]
            date = 'Today' 
        else:
            date = date_scrape[0]
            time = date_scrape[1]

        ticker_name = ticker.split('_')[0]
        parsed_news.append([ticker_name, date, time, text])

# Perform sentiment analysis
analyzer = SentimentIntensityAnalyzer()

# Create dataframe of news headlines with sentiment scores
columns = ['Ticker', 'Date', 'Time', 'Headline']
news = pd.DataFrame(parsed_news, columns=columns)
scores = news['Headline'].apply(analyzer.polarity_scores).tolist()
scores_df = pd.DataFrame(scores)

# Join sentiment scores to news dataframe
news = news.join(scores_df)

# Convert date to datetime object
news['Date'] = news['Date'].apply(lambda x: datetime.now().date() if x == 'Today' else x)  # Substitute "Today" with current date
news['Date'] = pd.to_datetime(news['Date'])
news = news.drop(columns=['Headline'])

# Group news by ticker and calculate mean sentiment for each
unique_tickers = news['Ticker'].unique().tolist()
mean_sentiments = []
for ticker in tickers:
    dataframe = news[news['Ticker'] == ticker]
    mean = round(dataframe['compound'].mean(), 2)
    mean_sentiments.append(mean)

# Create and display dataframe of tickers with mean sentiment scores
sentiments_df = pd.DataFrame(list(zip(tickers, mean_sentiments)), columns=['Ticker', 'Mean Sentiment'])
sentiments_df = sentiments_df.set_index('Ticker')
sentiments_df = sentiments_df.sort_values('Mean Sentiment', ascending=False)
print('\n')
print(sentiments_df)

Implement Auto-Trading

Hey @shashankvemuri . Amazing project, a lot of baseline features to be used in quant finance. I have some experience with quant and have developed a PPO DRL algorithm that looks promising. I am also planning to include GANS and CNN discriminator along with the news. Let's work together to see how can your baselines also be included to better predict the market direction.

I Need Help

Hi Shashankvemuri, I ran the code, and I get the following error. HTTPError: HTTP Error 403

I have entered the API that I generated in FMP.

I will be very grateful for your help.

image

On trading view

Hi Shashank,
I can not see which files/packages need to install before using fiance project?
Can you pelase let me know that step by step ?

Potential performance issue: .to_datetime in pandas below 2.1

Issue Description:

Hello.
I have discovered a performance degradation in the .to_datetime function of pandas version 2.0.3. .to_datetime doesn't recognize Arrow date time dtypes and converts them again. And I noticed that some parts of the repository depend on the pandas version 2.0.3. I found that many files such as stock_analysis/sp500_cot_sentiment_analysis.py, technical_indicators/candle_abs_returns.py used the influenced api. There may be more files using the influenced api. I am not sure whether this performance problem in pandas will affect this repository. Here are some discussions on pandas GitHub related to this issue, including #52545 and #53301.

Reproducible Example in pandas

In [3]: dr = pd.date_range("2019-12-31", periods=1_000_000, freq="s").astype(pd.ArrowDtype(pa.timestamp(unit="ns")))

In [4]: %timeit pd.to_datetime(dr)
1.84 s ± 8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

Suggestion

I would recommend considering an upgrade to a different version of pandas >= 2.1 or exploring other solutions to optimize the performance.
Any other workarounds or solutions would be greatly appreciated.
Thank you!

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.