Python For Finance

I built a few python scripts to find undervalued companies. Anyone else use python to automate big data pulls?

Attached: PYFI.jpg (196x257, 13K)

Other urls found in this thread:

eoddata.com/symbols.aspx
financials.morningstar.com/
zacks.com/stocks
financials.morningstar.com/ajax/ReportProcess4CSV.html?'
financials.morningstar.com/finan/ajax/exportKR2CSV.html?'
github.com/wilsonfreitas/awesome-quant
anaconda.com/download/#macos
pastebin.com/Jni3vDMY
pastebin.com/7NtV0GaN
pastebin.com/6eFyPhTn
pastebin.com/jUYDjGMj
pastebin.com/v0TE8jXL
quantopian.com
youtube.com/watch?v=ng_Rz6VoYu4
scipy-lectures.org/index.html
twitter.com/AnonBabble

any tips how to use python in crypto

This is cool as hell OP is based

Attached: cowsSacred.png (361x240, 170K)

what libraries did you use?

kek, actually got that book for Christmas. Have it in front of me now

Where'd you get your data from? Bloomberg?

where to start if i want to learn python?

Do you have any experience with programming at all?

I haven't done anything with python for crypto. Just pulled all companies in the NYSE and NASDAQ.

I used pandas, numby and a couple others. if you want i can post the scripts.

Please do.

nope, just VBA (kek)

I pulled all the companies for NASDAQ/NYSE from. eoddata.com/symbols.aspx

The financial ratios are pulled from financials.morningstar.com/ (this is where the Earnings Per Share data is pulled)

zacks.com/stocks is used to pull the close price.

I know other sites can be accessed for data. this is what I have been using.

lmao, well when I was learning the three most helpful things I found were:

1. I started with Python: Crash Course by Eric Matthes to get the basics down
2. tutorialspoint.com for their Python 3 tutorial to get some of the nuisances and deeper features
3. and I used hackerrank.com to practice on their challenges

Use google to find the answers for smaller questions that you're not sure about (i.e. they're asking for a two decimal answer and you need to turn your float into a number with two decimals after the point).

thanks man

So I found a great course that gave me my start with this, it was on the pirate bay. search GET RICH SLOW - Step by step value investing with Python.

it has the videos, python scripts and excel spread sheet formals to complete the process of doing the data pulls and then using excel to get the valuations of the companies.

If your using Mac you may need to change the format of the file path but this script will pull the market caps for all companies in your excel file(all companies in the NYSE/NASDAQ or what ever exchange you want)

Sorry for the image but not enough room to paste it.

Attached: Market Cap Pull.png (2010x1612, 495K)

Could ya post em that’s be cool im learning python rn, first anguage

hey Zack

Attached: 1544960788943.jpg (500x374, 27K)

This one pulls all the EPS data for companies in your excel file. These pulls can take a few hours but if your high speed you can learn how to setup an amazon virtual machine with AWS ECU2 to let it run with your python programs with using your own computers resources.

Here is the Part 1 so you can copy pasta it.

# -*- coding: utf-8 -*-

from bs4 import BeautifulSoup
import urllib2
import numpy as np
import pandas as pd
import csv
from os import chdir
from time import time
from time import sleep

#------------------function to open the webpage-----------------
def GetData(ticker,findf):
#test to see if excahnge works "NYS" vs "NAS"-----------------------------
istst = (r'financials.morningstar.com/ajax/ReportProcess4CSV.html?'
r'&t=XNYS:' + ticker + r'®ion=usa&culture=en-US&cur=&reportType=is'+
r'&period=12&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&'+
r'rounding=3&view=raw&r=519204&denominatorView=raw&number=3')
header = {'User-Agent': 'Mozilla/5.0'} #Needed to prevent 403 error on Wikipedia
req = urllib2.Request(istst,headers=header)
page = urllib2.urlopen(req)
soup = BeautifulSoup(page, "lxml")
if len(soup) == 0:
ex = "NAS"
else:
ex = "NYS"
#assign the tickers
finwiki = (r'financials.morningstar.com/finan/ajax/exportKR2CSV.html?'
r'&callback=?&t=X'+ex+r':'+ticker+r'®ion=usa&culture=en-US&cur=&order=asc')
#links = [iswiki,bswiki,cfwiki,finwiki] #putting it all in a list
links = [finwiki] #putting it all in a list
#-----------------the rest of the code----------------
header = {'User-Agent': 'Mozilla/5.0'} #Needed to prevent 403 error on Wikipedia
req = urllib2.Request(links[0],headers=header)
page = urllib2.urlopen(req)
soup = BeautifulSoup(page, "lxml")
#---------------End of Part 1----------------

Part 2 of the EPS Scraper...remember to paste them all into your own Python editor.

#------------------returned the I&E----------
dat = soup.get_text() #pulls out just the text from the csv
#just do a text thing
#so create a file?
target = open('test01.csv', 'w')
target.write(dat)
target.close()
#can use skip rows?
#---------------

#read it in as a dataframe? skip the first row
df = pd.read_csv("test01.csv",header = 2,index_col=False) #, index_col=False
df.index = df['Unnamed: 0']
df = df.drop(['Unnamed: 0'], axis = 1)
df.index.names = ['Desc'] #rename the index
#print(isdf)
#to return the lines that I need
dfeps = df.loc[['Earnings Per Share USD']].copy() #,'Return on Assets %'
#so the technique to change the name is to add a column
dfeps['name'] = ticker
dfeps.index = dfeps['name']
del dfeps['name']
#change the name of the colums to last years, to make it consistant?
#then can do valuation in excel...no need to pull in price at each period
################now combine the two df's###############
if j==0:
findf = dfeps
else:
findf = findf.append(dfeps) #the merged BS/IS
return findf
#---------------End of Part 2------------

github.com/wilsonfreitas/awesome-quant

is a really good resource, I would bookmark it.

Attached: 16545631763675698165656145612316768623415615656656546105321565252342.jpg (399x357, 42K)

OP, take this image into heart. You can do literally anything with Python that you would do regularly. However, if you're new to business, you should learn more about business before trying to jump into programming. Figure out what you want to do.

That being said, learning Python is probably one of the best career moves. Best of luck.

Attached: 1341268934615.jpg (782x528, 52K)

There are a few others sripts that pull data like the last two years of the close price, the stock price when the earnings where reported and one the creates charts. Using all the big data scaped by the programs I can use excel to create the Discounted Cash Flow model and apply to all the stocks. the ultimate product is a list of companies showing what their value should be based on the past 5 years of earning and prices and what they are currently trading at. If the stock is currently trading below its valuation then its undervalued and can be analyzed further. if its trading over its price its overvalued and can be targeted for shorts.
This is more that goes into it like current market cycles and other factors affecting the company.
Investors Business Daily is a great way to narrow down the list of undervalued companies to give you the best of the best.

Attached: Undervaluation List.png (1084x1346, 292K)

Thank You! We never stop learning.

I have that book lying around somewhere but never really got the chance to open it--I'm a Swift/Object-C applecuck XCode brainlet so I have to ask: where does one even write Python scripts, particularly for finance? I did the codecademy courses for it some years back and quite liked it, though courses like that never really tell you where to go after or give you proper tutorials for IDEs

Attached: VERY slow in the head.png (226x223, 6K)

anaconda.com/download/#macos

This is the editor I use, you want to use the spider editor found in the application.

sublime

this one has been running for about 7 hours and still has about 2 more...

Attached: Screen Shot 2018-12-30 at 10.50.51 PM.png (2876x1755, 940K)

Fascinating thread. Sure would love to automate some of these tasks but never managed to get past the basics in programming. Every course and book goes from fully internal to suddenly pulling into from other areas without explaining how to actually do that.

>knows python
>doesnt know pastebin
bruh

Why not just use a stock screener like investing.com? I mean, I like python, but what do you intend to do? Algorithmic trading?

You are too smart for me,
pastebin.com/Jni3vDMY Market Cap Pull
pastebin.com/7NtV0GaN EPS Scraper
pastebin.com/6eFyPhTn Price at EPS
pastebin.com/jUYDjGMj Price history current and two years prior
pastebin.com/v0TE8jXL

here is everything i'm using.

Could use Bloomberg to keep active tabs on a watchlist generated the night or week before.

500,000 queries a day iirc to Bloomberg on the free API.

Whats the best language for trading bots?

Awesome thread, good work OP.

I want more options to manipulate the data so I pull big amounts of stock data for information like prices over multiple years, cash flow amounts, balance statement information, etc. That is not commonly found on free services.

Then I use valuation models not available on free services. If you can find a site that use discount cash flow method to calculate valuations for any stock on any exchange I will use it.

I hear Python is one of the more popular websites. I would check out this site to learn more about algorithmic trading: quantopian.com
also Think or Swim platform I think is okay but I you may need to do some research.

I need to come on here more often, that sounds like common sense as a source to pull from.

agreed, I wish more posts on this board were of this quality

>feel really comfortable with python, enough to write what everybody here has posted on my own
>literally 0 knowledge how to spot undervalued companies or investment opportunities looking at data
Crossed the ocean and drowned in the puddle lads

Complete brainlet shit head here. Can anyone here tell me what this is and how i can join this? Im a business student with alot of free time and this looks interesting. Never did programming or wizardry ever in my life. The most I did was if logic gates for a theme park during high school computer class. Where do I start? And any material would be appreciated. Thank frens

Attached: 1546149910263.jpg (600x484, 25K)

I'm brainlet-tier right along with you fren, and programming for finance is definitely interesting and potentially profitable. In programming there exist different languages with different strengths and weaknesses, though Python is especially renowned for its applications in science and big data (in this case finance). A great starting point to programming in general is Codecademy, they have a free Python course last I checked that is totally in-browser. The learning curve in programming IMO is not at the beginner or advanced level but rather at the intermediate level--you get the basics of a language but don't really know where to go on your own. With this, I would also like more frens to expand upon this subject

make me a bot like this

youtube.com/watch?v=ng_Rz6VoYu4

Also, since this is a based Python thread, is there any real merit to sticking with Python 2? Or is the community all about Python 3 full steam ahead?

Thanks fren I'll look intk that

Dont know what hes talking about except the trailing sell
But it seems doable
Where should I start to expand my knowledge to this kind of stuff from "buy low sell high lol"?

PyAlgoTrade

How much time to learn python without programing experience?
Im very depressed in my work, i need to move, i can study for 4 years with my saves.

Python 3

Not many people know this.
But THIS is how you properly share code. As a screenshot in Jow Forums.

Only other viable way is making a photograph of a printed out page and sending it via postcard.

Attached: 1546041604682.jpg (563x517, 90K)

Thx for all the tips guis!
Can't all those things be done with java/Scala as well? Too much code?

I made my own algo trading platform and front-end in Node.js, which has been blazing fast and highly flexible for my high-frequency needs so far.
Brokers trading and live/historic data sourcing and high precision paper order execution simulation (can simulate same-price L2 queue, and partial fills) for any exchange I care to implement (I've provided impl's for Binance and Bitstamp so far).
You write a strategy script in javascript in your browser, submit it to the engine which sandboxes your script in a VM, runs it for however long you want, live or paper trading, and you can see all the stuff it's doing. Running a few low volume strat's on there for the past couple months - pretty comfy.
Node.js has been great t b h, and making the web front-end for it was easier as a result.

kek, was thinking the same

> what is pastebin

Where to cop good models?

> bare except
absolutely disgusting

I use ruby, mainly to help calculate my taxes though.

Used it for automatic SEC filing notifications.
Also automated my front end web job and haven't told my boss. Pretty cozy.

half a year with good books/tutorials ( at leisurely pace even )

Took me about a year, but I started with PRAW and Reddit bots.
Just Google PRAW in 5 minutes Reddit or something.
From there, you can cut your teeth on a few more bots. I had a few with custom dictionaries and would reply to comments, then tell them to fuck off or give praise if they responded to my comment. Basically have fun trolling. Then read Automate the Boring Stuff.
There's no panacea, no magic book. Use your knowledge and come up with needs that fit your life and learn how fulfill them with Python via Google and cussing.

Implying though that the local market will actually give a damn.

I've been trying to move from front end to Jr back end for the past year and can't catch anybody's eye. I'm in a hick town though, so ymmv

Here are some good basics:
scipy-lectures.org/index.html
Most important is trail and error, learn by exploration.