Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
76 views

Career Hackers: Hack Your Career Today Python in Finance

This document introduces a book about recent developments in financial technology in banking. It discusses how major banks like Citi and JP Morgan are adopting fintech solutions. It also advertises externship programs where students can gain technical training and work experience relevant to careers in finance. The book covers Python programming fundamentals needed for fintech roles, including variables, data types, operators, and control flow statements.

Uploaded by

Trieu Nam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
76 views

Career Hackers: Hack Your Career Today Python in Finance

This document introduces a book about recent developments in financial technology in banking. It discusses how major banks like Citi and JP Morgan are adopting fintech solutions. It also advertises externship programs where students can gain technical training and work experience relevant to careers in finance. The book covers Python programming fundamentals needed for fintech roles, including variables, data types, operators, and control flow statements.

Uploaded by

Trieu Nam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Career Hackers

Hack Your Career Today

Python in Finance
Fintech Development in Banking

Introduction
Dear students,

Thank you for supporting our Giveaway Campaigns and thank you so much for your
continual support to Career Hackers. We are very grateful for your support.

This book is geared towards helping you understand more about recent
development for financial technology in banking industry. We have outlined the
major development in banks like Citi, JP Morgan and more.

We hope you will enjoy this book. We wish you all the best in this recruitment
season.

If you want technical training plus real work experience on your resume, you can
take a look at our Global Markets Externship or Management Consulting Externship.
Past students have ended up at large financial institutions like Point72 and Morgan
Stanley.

Regards,
Career Hackers Team

careerhackers.io Career.Hackers Career.Hackers pg. 2


Table of Contents

1. Introduction and Overview ................................................................... 3


2. Variables.......................................................................................... 4
3. Comments ........................................................................................ 4
4. Data Types ....................................................................................... 5
a) Numbers ................................................................................................. 5
b) Strings ................................................................................................... 5
c) Lists ...................................................................................................... 7
d) Tuples .................................................................................................... 8
e) Dictionaries ............................................................................................. 9
5. Operators ....................................................................................... 10
6. If-else Statements ............................................................................ 11
7. Functions ....................................................................................... 18
1. Introduction and Overview

Python is a general-purpose high-level programming language that supports Object Oriented


programming approach to develop applications. Python is simple to use, easy to learn and arguably
one of the best programming languages right now. Python has a lot of features and some of them
are listed below.

1. Easy to Learn and User Friendly

2. Expressive Language

3. Free and Open Source

4. Object- Oriented Language

5. Extensible

6. Large Standard Library

7. Python is Portable language

8. Interpreted Language

9. GUI Programming Support

10. High-Level Language

PyCharm is a cross-platform IDE, and hence it can be installed on a variety of operating systems.
In this section of the book, we will cover the installation process of PyCharm on Windows,
MacOS, CentOS, and Ubuntu where you can write python code. In order to install PyCharm on
Windows Operating System, visit the link
https://www.jetbrains.com/pycharm/download/downloadthanks.html?platform=windows to
download the executable installer. Then install PyCharm by following the steps on the install
wizard and you are ready to start coding!

This e-book will give you a basic idea of how python works and will put you in a position to carry
on further learning by yourself. So, let’s begin this wonderful journey of a world of endless
possibilities - “Python”.
2. Variables

Variables are containers for storing data values. Unlike other programming languages, Python
has no command for declaring a variable. A variable is created the moment you first assign a
value to it. However, there are some rules when it comes to declaring variables:
• The variable’s first character should be an alphabet or underscore(_)
• All the characters except the first character may be an alphabet of lower-case(a-z),
upper-case (A-Z), underscore or digit (0-9).
• The identifier name cannot contain any white space or any special characters (!, @, #, %,
^, &, *)
• The identifier name cannot be the same as a keyword that is defined in the language.
• The identifier names are case sensitive
Examples of valid identifiers: d345, _number, f_1, number
In python when declaring a variable, there is no rule that we have to declare the variable before
using the application. We are allowed to create the variable at the time it is required. The (=)
operator is used to assign a value to the variable as can be seen below:
d=5
name=’jack’
name_id=787

3. Comments

Comments are parts of the code that are ignored by the compiler and are not considered
when you execute a code. Comments can be extremely helpful for a variety of purposes
and provide many advantages. They make the code more presentable and informative and
provide the user/third-party (someone else who is reading the code) a sense of what is
going on in different parts of the code if it's properly commented. Commenting your code
is considered a good practice and everyone should include some informative comments
while writing codes.
There are two types of comments:
1. Single Line Comments
2. Multi Line Comments

Single Line Comments:


These begin with the symbol ‘#’ and tell the compiler to ignore anything that follows the
# symbol in that particular line. For example:
Multi Line Comments:

These comments span over multiple lines and are strings that are enclosed within triple
quotes. For example:

Note: Triple quoted strings are considered as docstrings in python but when they are not
docstrings (the first line in a class/function/module), they are ignored. This will be
revisited again when we discuss “Functions” later.

4. Data Types

A variable can hold different types of values. There are five data types in Python. They are:
1. Numbers
2. String
3. List
4. Tuple
5. Dictionaries

a) Numbers
• Number stores numeric values. Python creates number objects when a number is assigned to
a variable.
o For example: x=2, y=10 # x and y are number objects
• The 4 types of numeric data that python supports are:
o int (3, 4, 8, 1000)
o long (long integers that are used)
o float (used to store floating point numbers)
o complex (used to store complex numbers)

b) Strings

Strings are one of the most commonly encountered data types in Python. They can store a single
character or a sequence of characters (alphabets, digits, special characters, etc.). Strings can be
created by enclosing characters in quotes, either single or double.
o For example:

-> Accessing Values in Strings using Indices

In python, characters are treated as strings of unit length. To access values in strings, we use
their indices in the following way:

OUTPUT

As shown above, a part of the string can also be accessed using a colon (“:”) and specifying the
starting and terminating index before and after the colon.

-> Concatenating Strings

Concatenation of strings means adding two strings together. It can be done in many ways which
has been shown through the following examples:

Example 1:

OUTPUT

Example 2:
This example uses accessing values in strings method along with concatenation. An interesting
thing to notice is that you can leave the starting or terminating index blank which makes the
compiler assume that the starting index is 0 or terminating index is the length of the string
respectively.

OUTPUT

Example 3:

Strings can be concatenated with a sequence of characters in double or single quotes in the print
statement.

OUTPUT

c) Lists

If you have ever learned the C programming language, then you must have heard about arrays.
Lists are like arrays, but lists can contain data of different types separated by commas ‘,’ and
enclosed between square brackets []. In order to get an output, we use the print() function. You
can also find in the below diagram how list indexes are given in a list and some code snippets
below with the output.
Length = 5

‘p’ ‘r’ ‘o’ ‘b’ ‘e’

index 0 1 2 3 4

negative index -5 -4 -3 -2 -1

OUTPUT

d) Tuples

A tuple is very similar to a list in many ways. Just like lists, tuples also contain a collection of
items that have each been separated with a comma (,) and the encloses in parenthesis (). The
size and the value of items of a tuple cannot be modified and so is only a read only data structure.

Now let’s look at a simple example:

OUTPUT
e) Dictionaries

A dictionary is an ordered collection of a key-value pair of items. It is more like an associative


array where each of the keys stores a specific value. A key can hold any type of data and the
value is a python object. The items in the dictionary are separated with a comma (,) and enclosed
within curly braces ({}).

Now let’s again look at an example

OUTPUT
5. Operators

Operator can be defined as a symbol that performs a particular operation between two operands.
Python provides a variety of operators. Here are some of them:

Arithmetic Operators Comparison Operators


• Addition (+) • ==
• Subtraction (-) • !=
• <=
• Divide (/) • >=
• Multiplication (*) • <>
• >
• Reminder (%)
• <
• Exponent (**)

Operator Precedence

• **

• + - (unary plus and minus) Logical Operators


• * / % // • and
• or
• + - (Binary plus and minus) • not

• >><<

• &

• ^|

• <= < > > =


6. If-else Statements

In almost all programming languages, decision making is the most important feature. Decision
making enables us to run a specific piece segment of code for any particular decision. In this case,
the decisions are made based on whether the given conditions are satisfied or not. Condition
checking is the foundation behind decision making.

In python, decision making is performed by the following statements.

STATEMENT DESCRIPTION

The if statement is used to test a specific condition. If the condition is true,


If statement
then the code block will be executed.

The if else statement provides the code block for both the cases when the
If- else
condition is true, and the condition is false. If the condition provided in the
statement
if statement is false, then the ‘else’ statement will be executed.

Note- input() is the statement that allows a user to enter data.

Condition

If condition
is true

If condition
is false
if block

else block
Now let’s look at a simple example that involves if statements.

OUTPUT

Find below two different outputs for 2 different data inputs.

In addition to just “if” and else, “elif” statements can also be used for decision making. “elif”
statements are only executed if the “if” statements before them are false.

Condition

Condition

Condition

Statement 1 Statement 2 Statement 3


3

Next Statement
Let’s look at another example:

Find below the different outputs for the different inputs.

OUTPUT
Loops
Loops play a key role in any programming language as the execution of a particular code may have
to be done several times. For this purpose, programming languages provide various types of loops
which help to repeat the same code for a specific number of times. The concept of loops can be
understood in the below diagram.

Loop Body

If condition is
Condition true

If condition
is false

Advantages of loops

1. Provides code reusability


2. When using loops, we don’t need to write the same code again and again
3. We can transverse over the elements of data structures.

Loop
Description
Statement

For loops are usually used when we need to execute a particular part of a code
for loop
until a given condition is satisfied. It is usually better to use the for loop when

As opposed to for loops, we use while loops in instances where we don’t know
While loop the exact number of iterations in advance. The code block will be executed
until the code the condition in the while loop is satisfied.

For Loops
Python for loops are commonly used to traverse in data structures like list, tuple or dictionary. As
the definition of “for” loop was explained in the above table, let's now look at the logic behind the
“for” loop and an example.

If no item is left in
the sequence
Item from the
sequence

Next Item

Loop Body

Now let’s look at some examples.

OUTPUT OUTPUT

Nested For Loops


In python we can nest any number of loops within one for loop. The inner loop is executed n number
of times for every iteration of the outer loop. Now let’s look at the syntax for a nested for loop in
python.

Let i and j be 2 iterating variables,

for i in sequence:

for j in sequence:

#block of statements

#other statements

Now let’s look at some examples:

Find below the outputs for 2 different inputs:

OUTPUTS

While Loops

The python “while” loop as mentioned in the table earlier, allows a block of code to be executed as
long as the given condition is true. It can be seen as a repeating if statement. The “while” loop is
mostly used in instances where the number of iterations is usually not known in advance.
Now let’s look at the syntax.

while expression:

statements

Next let’s look at the logic of the while loop.

If Condition is false
Condition

If Condition is true

Loop Body

Next let’s look at some examples:


In this example observe how the
the “print(i)” line of code is
executed up to and including i=5

OUTPUT

OUTPUT

7. Functions

Functions are blocks of code that can be defined in a program and reused to perform a specific
action/task. Functions provide added modularity and save time because of high degree of
reusability.

Types of Functions:

Functions can be divided into the following two parts:


1. Built-in Functions: The functions provided by Python to the users fall under this category.
For example - print(), len(), etc.

2. User-Defined Functions: These are the functions that the users can define for themselves
according to particular needs.

Defining Functions:

It is the process of letting python know that the part of the code you are about to type is a
function. There are some simple rules that one should follow while defining functions:

1. All functions begin with the keyword def followed by the name of the function and
parentheses (( )).

2. The body of the function starts after a colon (:) and it is indented.

3. The first line of a function is optional - the documentation string of the function or
docstring.

4. A function ends with a return statement, optionally returning back a value to the caller.
A return statement with no arguments is the same as return None.

Syntax:

def functionname(parameters):
"""function_docstring"""
function_body
return_statement

Example of a function:

Calling a Function:

Defining a function only gives it a name, specifies the parameters that are to be included in the
function and structures the blocks of code. Now that you have defined a function, we want to use
it for the task we defined it for. You can execute a function (make it do what it is supposed to
do) by calling it from another function or directly from the python prompt.

The above function “square” takes an argument (“x”) and returns the square of the input to the
caller. Here is how you can execute this function to give you the desired output:

OUTPUT

As you can see, when we give 3 as the argument of the function “square”, it returns the square
of the number 3, i.e., 9.

The Concept of Required/Default Arguments:

Required Arguments:

These are the arguments passed to a function in correct order as specified while defining a
function. The number of arguments in the function call should match exactly with the function
definition.

The following example illustrates how you have to provide the two arguments ‘x’ and ‘y’ in order
to execute the function ‘_square_and_cube’ with two required arguments:
OUTPUT

If you do not provide a function with all the required arguments while calling it, you will encounter
an error.

When you try to call the above function “square_and_cube” as shown below, you will get the
following error:

OUTPUT

As you can see, the error tells you that an argument is missing and in order to properly call the
function, you have to provide all the arguments.

Default Arguments:
A default argument is an argument that assumes a specified value (while defining the function) if
a value is not provided while calling the function. The following example illustrates how you can
use default arguments in the definition of a function:

As you can see above, a default argument for ‘y’ has been provided in the function definition.
The first function call provides both the arguments while the second function call only provides
the ‘x’ argument. The following shows how the output varies because of default arguments:

When the argument for ’y’ is not provided, the function automatically assumes the input to be ‘4’
which has been specified in the function definition.
There you go for the Introduction to Python Programming. It is completely fine that you don’t
recite any of the above as long as you can now think from a programming perspective, a more
critical perspective and, most importantly, start applying it to whatever context you can at work.

Good luck in your career hacking journey!


Fintech Development in Banking

About Us
Funded by Hong Kong Science and Technology Park, Career Hackers aims
to democratize career secrets by connecting students with industry
insiders. All the insiders need to go through a vetting process where we
verified the firms that they are working in and the positions that they
are holding, in order to make sure every information on our platform is
verified.

Global Markets Externship: A combination of both training and real work


experience. Past students ended up at Point72, PIMCO, Morgan Stanley
and Citi. Mentored by ex-Goldman Sachs Executive Director and now a
Hedge Fund Manager, this is an intensive experience where you actually
get your hands dirty and construct a portfolio from scratch. You will
receive a reference letter issued by LBN Advisers, an award-winning
hedge fund, by the end, with a hedge fund experience on your resume.

Management Consulting Externship: Partnered with Elyx Consulting,


whose Fortune 500 clients like HSBC and MasterCard, this program
offers you immersive experience in projects ranging from strategy to
operations and more. You will work on tasks like pricing evaluation and
case analysis.

We have more exciting news coming. Remember to stay tuned in out


platform and check them out!

Once again, thank you for your support to Career Hackers and wish you
all the best.

careerhackers.io Career.Hackers Career.Hackers pg. 7

You might also like