How to cite or refer to programming codes in a non Computer Science Master's Thesis? I am writing my Thesis in finance field and I am using Machine learning methods. Therefore, I wrote many Python and R scripts for collecting data, cleaning it and applying some statstics. 


should I reference my own code that I wrote? if yes can you please tell me how?
should I reference all the libraries that I've used during my work?


Thanks
The standard way is to upload the code in a public repository so that everyone can use your code. In the thesis, you can refer to your repository in the footnote/endnote. 

What you really need to cite is the papers/books which introduce the used methods first. The need to cite a library is when it has a specific configuration and it is likely that it outputs different result, such as the method which requires a probabilistic sampling. Here, the output will be different based on the used method. 

Back to your case and responding to your questions: 


You can publish all the materials of your work in a public repository and refer to it by citing the link (preferably in the footnote). It is unprofessional to add the code in the appendix (unless it is short and in pseudo-code).
You don't need to cite the libraries but the papers of the methods that are implemented in these libraries. If the library has a specific configuration, you can mention it in the text or cite the library (very rare cases).