tinyurl.com/sunbingo-uk

Tag Archives: Python

RMBS Prototype Model in Python

Parameters Parameters including : Total balance , Attach point, mortgage rate , Tranche Rate, Payment term and Prepayment CPR .  Cash Flow Chart result: Full code(2 functions): def rmbs_show(self): self.clr_update_frame() Label( self.update_frame, text="CPR" ).grid( row = 0, column= 0 ) w = Scale( self.update_frame, from_=0.01, to=0.20, resolution = 0.005, orient=HORIZONTAL, variable=self.rmbs_cpr, showvalue = True ) w.grid(row = Read more [...]

Conditional Checking in Python

When story begins In Python , there is a shortcut in conditional checking, I didn't take much care about the difference of below form of conditional syntax : if var :     stmt; if var is not None :     stmt; if var != None:     stmt; Explanation behind the scene is an analogy to difference of  an empty string "" and NULL in a database . ""  is an empty string but means something, NULL is nothing means nothing . In Python world ,  None equals NULL in Database , that's why "" == Read more [...]

Constraints on Arguments in Python

When Dynamic Type comes to Trouble As a dynamic programming languages , Python don't have a type on variables , as well as a arguments . This feature save us a lot workload and it enable us to focus on logical of program . def add(x, y): return x+y print add(5,6) >> 11 print add("D","E") >> "DE" print add(5.0, 6) >> 11.0 Above function is straightforward and works fine if x and y are passed with int/ float/ string . But things may Read more [...]

[译文]Decorators and Functional Python[draft]

Original blog post wrote by Brian Holdefehr. This is a Chinese version of original post . 本文原文作者 Brian Holdefehr。若有不足,敬请斧正。 装饰器(Decorators) 是Python众多强大特性之一。装饰器除了本身编程语法上的作用之外,另外提供了一种有趣思维方式——"函数化"思维(a functional way) 我会从头开始介绍介绍装饰器的工作原理,接着会介绍几个必须了解的基本概念。之后,我们会详细深入探索一些装饰器实例以及其工作方式。最后我们会讨论一些装饰器的高阶应用,例如参数化装饰器(optional Read more [...]

Get Stock Quote Price API from Yahoo Finance via Python

Difference against Google Finance / Sina.com Yahoo provide more rich function regarding to the Stock API than Google / Sina.com does. particular ,it provide customize return format which customized by supply  a parameter in calling URL . Full parameter specification pls refer to this link .(credit to  Kelly Elias ) . 200 calls per second , you will be warned if you exceed this limits csv file returned No market depth as SIna.com provide Provide stock indication such as " Earnings Read more [...]

Get Stock Quote from Goolge Web API via Python

Background Google has officially announce that it won't sustain ongoing of Finance API, but there still a available API via URL API . Return data from web server is xml format . We need to parse the return text in Python and extract data . Get the Stock Data Google Web API format (  http://www.google.com/ig/api?stock=C ) , this will request market data for security code "C" ( Citigroup  :) )  xml return result: <xml_api_reply version="1"> <finance module_id="0" Read more [...]

Get Security Quote of Chinese Market from Sina.com via Python

Intro Although articles have been written about calling security quote API of Sina.com . I'd like to take a dive into it via Python and try to setup a OO implementation.  Sina.com API will offer  5-th market depth prices of Chinese Shanghai / Shenzhen Exchange Stock in real time style . API structure calling Sina.com Stock API can be straightforward , just type "http://hq.sinajs.cn/list=sh601012" in browser address . call back will shown as below ( click to enlarge ):   Cracking Read more [...]

Project Euler Problem 26

Question A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given: 1/2 = 0.5 1/3 = 0.(3) 1/4 = 0.25 1/5 = 0.2 1/6 = 0.1(6) 1/7 = 0.(142857) 1/8 = 0.125 1/9 = 0.(1) 1/10 = 0.1 Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle. Find the value of d \lt1000 for which 1/d contains Read more [...]

Project Euler Question 14

Question: The following iterative sequence is defined for the set of positive integers: n \rightarrown/2 (n is even) n \rightarrow 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 \rightarrow 40 \rightarrow 20 \rightarrow10 \rightarrow 5 \rightarrow 16 \rightarrow 8 \rightarrow 4 \rightarrow 2 \rightarrow 1 It can be seen that this sequence (starting at 13 and finishing Read more [...]

Project Euler Question 29

Question: Consider all integer combinations of ab for 2 \leq a \leq 5 and 2 \leq b \leq 5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, 35=243 42=16, 43=64, 44=256, 45=1024 52=25, 53=125, 54=625, 55=3125 If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms: 4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125 How many distinct terms are in the sequence generated by ab for 2 \leq a \leq 100 Read more [...]