← Back to feed
Renewal·마흔의 생활코딩

[Python at Forty] The Learning Journey

NS
normalstory
cover image
YouTube 영상 미리보기YouTube
external media

Video summaries

  1. No summary yet.

Main study : follow-along practice with the book,  Python Securities Data Analysis <- 65%

 

파이썬 증권 데이터 분석

웹 스크레이핑으로 증권 데이터를 주기적으로 자동 수집, 분석, 자동 매매, 예측하는 전 과정을 파이썬으로 직접 구현한다. 그 과정에서 금융 데이터 처리 기본 라이브러리(팬더스)부터 주가 예

www.aladin.co.kr

 

 

Before, when I posted about coding studies, I tried to make them tutorial-like.

Looking back now, that's not great.

The problem isn't that there isn't enough information — it's that there's too much, isn't it? 

So I'll settle for just jotting down the main keywords and links.

 

 

Setup

64-bit Python (Windows x86-64 executable installer) download -> install Python (*check the option to auto-add to PATH)

-> from cmd install packages (pip install matplotlib, and pythonexe -m pip install --upgrade pip) *handling EnvironmentError

-> install packages for practice (save the list as a file and run it from cmd = pip install -r filename.txt)

-> 32-bit Python (Windows x86 executable installer) download -> install (*don't check the PATH option) 

 

 

Main references

  - Python — Polish the Basics,

  - python.org (kr)

  - Programmers — Python

 

 

Sub references

 - PyQt GUI for Stock Investing

 - Pat-pat Python

 - Securities Data Analysis (hands-on review + video)

 - Losskatsu's git.io

 

 

Main keywords  

pip install .. runs in the terminal, not in Python

empty list, dict, tuple, set

  - #list ls=[], #dict d={}, #tuple t=(), #set s=set()

List

  - append(), extend()

comprehension

dictionary

  - a.key(), a.values(), a.items(), a.clear(), a.get('key'), a.get('key','default comment')

  - f-string, {}, $s

set

  - no duplicates, no indexing, supports intersection/difference/union operations

  - much faster "lookup (if)" speed (for-loops are a bit slow) *timeit (speed test LB)

Lambda

built-in functions

Library = modules (.py files) and packages (folders)

   from module/datetime import method/datetime as alias/dt
   print(dt.now())
  myPackage.moduleA.functionA()
  package.module.function 

objects, instances, inheritance

requests python -m pip install requests

with ~ as file-object

SHA-256 import hashlib 

 

 

Basic math

squares and square roots

mean, variance, standard deviation 

linear regression model (cause x, continuous outcome y, measurement error e, expressing their relationship as a linear equation (line) : 

stats.linregress(df['target1'],df['target2']) )

variance, covariance, correlation coefficient, correlation 

 

 

Key indicator functions    

CAGR Compound Annual Growth Rate

def getGAGR(first,last,years): # compound annual growth / yearly compounded return (sales volume, user growth rate)
    return (last/first)**(1/years)-1

R1 Daily percent change daily rate of change (comparing two stocks at different prices)

R1 (today's rate of change) = (target.['column'].shift(1) - target.['column'] / target.['column'].shift(1) ) * 100

MDD Maximum Drawdown maximum loss drawdown

(low - high) / low

Sharpe Ratio  

(expected portfolio return - risk-free rate) / standard deviation of returns

Bollinger Bands  + related practice reference (Class101 — TimePercent)

upper Bollinger Band ubb = middle Bollinger Band + (2 × stdev)
middle Bollinger Band mbb  = 20-day moving average of close 
lower Bollinger Band lbb = middle Bollinger Band - (2 × stdev)

PerB (Price, Length, Mult, MaKind, [Optional]Pos) = %b  *additional reference
   = (price – lower) / (upper – lower) = (close - lbb) / (ubb - lbb)
     * Price: the base price data for the moving average (open, high, low, close)
     * Length: moving-average period
     * Mult: multiplier
     * MaKind: method for computing the moving average
     * (S: simple MA, E: exponential MA, W: weighted MA, A: cumulative MA)

Bandwidth
   = (upper – lower) / middle = (ubb - lbb) / mbb

MFI Money Flow Index cash-flow indicator

- uses typical price (not close) and volume (which leads price) as an indicator

RSI relative strength index 

 - RS = average upswing over n days / average downswing over n days
 - RSI = 100 - 100 / (1 + RS)

 

 

API, Library

Yahoo Finance

Korea Corporate Disclosure Channel

Naver Finance *handling crawler blocks

backtrader : bt.indicators.(reference)

 

 

 

Data analytics libraries

numpy numerical python | cmd > pip install numpy | examples

pandas | cmd > pip install pandas | describe(), Series, DataFrame (multiple Series combined under one index), regression analysis

SciPy (pronounced “Sigh Pie”) is a Python-based ecosystem of open-source software for mathematics, science, and engineering. In particular, these are some of the core packages | cmd > pip install scipy

html5lib  parsing HTML | cmd >pip install html5lib 

beautifulsoup4 a Python library for pulling data out of HTML and XML files | cmd >pip install beautifulsoup4 | example 1 example 2

 

 

Visualization

mplfinance 

matplotlib | cmd > pip install matplotlib | drawing images, drawing charts

plotly (& example: showing plot, plotly, and dash together on one page, plotly libraries )

D3.js

front-end framework

Django - (Vitor Freitas's blog)

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.