Contains a list of software utilities and programs for financial calculations.
-
Download the Historical Open, High, Low, Close security prices in a CSV format from Yahoo Financial Pages.
-
Generate annualized summaries of returns and volatilities with the moving averages of different securities with the data downloaded as CSV from Yahoo Finance.
-
Discounted Cash Flow Calculator that generates a cash flow chart with NPV from a CSV file.
-
Probability modeling of binary stock value expectations from sequence of buys or sells for a stock given a trading scenario for different proportions of informed and uninformed traders.
Python 3.5.0 or later.
Virtual environment packages with virtualenv
or anaconda
should be used for both Windows and Linux/BSD based systems.
After cloning the repository, install the required python packages using pip.
$ git clone https://github.com/SamSamhuns/financial-utility-programs
$ virtualenv venv
$ source venv/bin/source
$ pip install -r requirements.txt
Download a copy of this github repository. Two options are available after this:
-
Anaconda
is recommended for Windows system. Set up a virtual environment in Ananconda. Then use the following command in the anaconda prompt to install modules from requirements.txt.conda install --yes --file requirements.txt
-
Install
python
and add it to yourPATH
system variable. Then install thepip
package.
Then run the following commands.
pip install virtualenv
virtualenv venv
venv/Scripts/activate
pip install -r requirements.txt
Individual instructions for running the utility scripts are also present inside each python file. The instructions are equivalent for both Windows and Linux/BSD systems given that python has been added to the PATH system variable in Windows systems.
In Unix, Linux and other BSD based systems, use the following command in the bash shell to ensure python file is exeutable.
$ chmod u+x python_script.py
The CSV file name must entered as the first command line argument for the DCF calculation to work.
$ python3 main_DCF.py <yearly_discount_rate> <name_of_csv_file.csv>
A cash_flow_fig_png file will be generated that contains the cash flow diagram.
The Value Realization Model uses a simple model to predict the probability of a high value or a low value for a stock given the sequence of buys(asks being lifted) or sells(bids being hit). The script will prompt the user to enter a sequence of buy(s)/sell(s) like `bbssbs` or `BSBSBB`. And to enter the proportion of informed traders assumed to be present in the market.
Buy/sell sequences can also be entered through a text file containing these sequences as the first command line argument to the script_name.
$ python3 main_VRM.py <OPTIONAL-buy-sell-sequence.txt>
Yahoo stopped its old EOD data download API as of May 2017 after the acquisition by Verizon. Yahoo financial EOD data, however, still works on Yahoo financial pages. These download links uses a "crumb" for authentication with a cookie "B". This code is provided to obtain such matching cookie and crumb. This code also downloads end of day stock quote from Yahoo finance.
Once the cookie/crumb is obtained, the querying URL is as following:https://query1.finance.yahoo.com/v7/finance/download/TTTT?period1=pppppppp&period2=qqqqqqqq&interval=1mo&events=eeeeeeee&crumb=cccccccc
where
- TTTT - Ticker (e.g., DJI, AAPL, etc.)
- pppppppp - Period1 is the timestamp (POSIX time stamp) of the beginning date
- qqqqqqqq - Period2 is the timestamp (POSIX time stamp) of the ending date
- eeeeeeee - Event, can be one of 'history', 'div', or 'split'
- cccccccc - Crumb
The resulting CSV file is in the format:
Date, Open, High, Low, Close, Adj Close, Volume
The new API is different from the old API in several ways:
- In the older API, the data fields were not adjusted.
- In the new CSV files the
Close
is adjusted for both dividends and splits, while theOpen, High, Low
are only adjusted for splits. - The order of the rows for historical quote by the new API is chronical ( counter_chronical in the old API ).
- Some of the values are recorded as NULL in the new API.
To download the CSV returns file using a script.
$ python security_csv.py <ticker_symbol> <start_date_YYYYMMDD> <end_date_YYYYMMDD> <quote_or_dividend_or_split> <interval_1d_1wk_1mo>
A possible example query to get GOOGL stock quotes from Jan 15, 2014 to Jan 18 2018 given a monthly interval:
$ python security_csv.py GOOGL 20140115 20180118 quote 1mo
The Returns and Volatilities model takes security returns data imported from the Yahoo Finance API or downloaded from Yahoo Finance as a CSV file. The returns can be download from Yahoo Finance or the `security_csv.py` script can be used to directly download the return data in CSV.
To generate a summary of the returns and volatilities with their annualized calculations.
$ python main_RAV.py returns.csv
The returns.csv file must be in the same format downloaded from the Yahoo Finance historical prices section.
CSV file format Date, Open, High, Low, Close, Adj Close, Volume
- Python 3.6 - The Programming tool used
Version tracked directly with Git
- Samridha Shrestha
This project is licensed under the Apache 2.0 License - see the License.md file for details
- Python open source libraries
- Yahoo Finance
- GitHub user c0redumb repository on yahoo_quote_download
- Joel Hasbrouck, NYU Stern Principles of Securities Trading, FINC-UB.0049, Spring 201.