tag:blogger.com,1999:blog-5440415324855100362022-01-21T03:24:19.592-08:00too little, too late<small><a href="http://wbmh42.000webhostapp.com/page1.html">home</a> <a href="https://tsm2.blogspot.com">tsm2</a></small>Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.comBlogger194125tag:blogger.com,1999:blog-544041532485510036.post-39159378846064643062022-01-12T06:10:00.000-08:002022-01-12T06:10:23.406-08:00biomassThe EU is very proud of its renewable energy projects and in Germany up to 40% of electricity is produced from renewables. But what they usually don’t mention is that more than half of that is from biomass and the majority of biomass is actually wood chips, i.e. wood pellets made from trees. In fact trees are chopped down in North and South America (i.e. Amazon) to produce those wood chips, which are then burned in former coal plants.<br>
Obviously, burning wood puts as much CO2 into the atmosphere as burning coal, but in addition large numbers of trees are chopped down. The idea that this is renewable energy is completely idiotic, it would take 20 – 50 years to regrow those trees.<br>
<br>
So far the US is not doing this on the same scale, until <a href="https://news.mongabay.com/2021/11/scientists-urge-biden-to-remove-logging-fossil-fuels-biomass-from-budget-bills/">Build Back Better</a>.<br>
Watch <a href="https://www.youtube.com/watch?v=Zk11vI-7czE">Planet of the Humans</a> (fwd 52:15) to see who is behind those idiotic biomass projects in the US.<br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com0tag:blogger.com,1999:blog-544041532485510036.post-66275468919740446632021-10-22T03:39:00.000-07:002021-10-22T03:39:03.260-07:00<br>
<br>
<img src="https://1.bp.blogspot.com/-68wQo43cCAM/YXKUgCSlpZI/AAAAAAAAA00/8cq-Wepxdq4wmJPpdQ0tBGkvXqwXIdV4ACNcBGAsYHQ/s0/monkey.jpg"><br>
<br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.comtag:blogger.com,1999:blog-544041532485510036.post-82773252633423857642021-09-30T05:54:00.001-07:002021-09-30T05:54:33.732-07:001984
"I just finished re-reading Orwell's 1984, and if you haven't read it (or it's been a while), I can't recommend it enough.<br>
It has incredibly relevant and predictive elements that describe things we're starting to see in today's culture. Here are some examples ..." <br>
<a href="https://twitter.com/SarahADowney/status/1443031980447256581">Sarah A. Downey</a> <br>
<br>
The really scary part is that political polarization is so bad now that most people won't acknowledge the similarities ... <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com2tag:blogger.com,1999:blog-544041532485510036.post-52090085002291126572021-08-15T01:42:00.000-07:002021-08-15T01:42:06.999-07:00then and now<br>
<img width="400" data-original-height="648" data-original-width="699" src="https://1.bp.blogspot.com/-Zb6QKyHRDo4/YRjSzXZdJfI/AAAAAAAAA0k/Y6v_1Yld9Z0c7Jo3qHpJIDTQR45d8ePzQCNcBGAsYHQ/s400/evac.png"><br>
<br>Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.comtag:blogger.com,1999:blog-544041532485510036.post-14076897365837165132021-08-03T03:46:00.004-07:002021-08-03T03:48:20.975-07:00taking bids now ...<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
Recently, artist <a href="https://news.artnet.com/art-world/italian-artist-auctioned-off-invisible-sculpture-18300-literally-made-nothing-1976181">Salvatore Garau</a> sold an 'immaterial sculpture' for 15,000 Euros (about 18,300 USD).<br>
After thinking long and hard, I made the difficult decision to auction off the above masterpiece from the artist formerly known as Daily Llama, which I obtained many years ago. I am taking bids now ... <br>
However, I reserve the right to sell the other masterpiece from the same artist as an NFT.<br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com4tag:blogger.com,1999:blog-544041532485510036.post-13553819549633464192021-07-23T06:09:00.001-07:002021-07-23T06:12:18.673-07:00Apollo 11In 1969 'the Eagle has landed' on the Moon and a few days later the upper section of the lunar module brought Armstrong and Aldrin back to the command and service module, which finally brought the astronauts back to Earth. <br>
But what happened to the lunar module? Does it still circle the Moon five decades later? <br>
If you find this question interesting you may like <a href="https://www.youtube.com/watch?v=dBHbLV7xEhc">this YouTube video</a>. <br>
I think it is a great example of what dedicated space and science enthusiasts can do ... <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com0tag:blogger.com,1999:blog-544041532485510036.post-26289982108114434542021-07-05T04:48:00.004-07:002021-07-05T04:51:40.735-07:00hyperpowerConsider the equation x<sup>x<sup>x<sup><sup>.<sup>.</sup></sup></sup></sup></sup> = 2. <br>
How do you find x in this iterated exponentiation, a.k.a hyperpower? <br>
The solution is quite easy: Consider the 'tower' above the bottom x, ie. x<sup>x<sup><sup>.<sup>.</sup></sup></sup></sup>.<br>
But it is the same as the original 'tower', so we know it is 2.<br>
Therefore x<sup>2</sup> = 2 and it follows that x = sqrt(2). <br>
<br>
But there is a problem if we now consider the equation x<sup>x<sup>x<sup><sup>.<sup>.</sup></sup></sup></sup></sup> = 4. <br>
Using the same argument we find x<sup>4</sup> = 4, with the same solution x = sqrt(2). <br>
Clearly there is a contradiction; it seems that we just proved that 2 = 4 if we equate the 'towers' of sqrt(2). <br>
<br>
I found this math exercise and the solution to the puzzle <a href="https://www.youtube.com/watch?v=DmP3sFIZ0XE">here</a>. <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com0tag:blogger.com,1999:blog-544041532485510036.post-32365700394463902372021-06-25T11:37:00.000-07:002021-06-25T11:37:17.213-07:00failureWe tend to think about the history of science as a series of breakthroughs and successes, from Galileo to Einstein ... <br>
But mistakes and failure were always part of it, from Galileo's explanation of the tides to Einstein's unified field theories.<br>
In physics there were Blondlot's N-rays, planet Vulcan, Fermi's trans-uranium (he even got a Nobel for it [*]) and many more -
but every science has its fair share.<br>
<br>
A few years ago I read <a href="https://www.amazon.com/When-Science-Goes-Wrong-Discovery/dp/0452289327">When Science Goes Wong</a>, an entertaining little book about big
blunders of science. <br>
If there should ever be a new edition, the <a href="http://capitalistimperialistpig.blogspot.com/2021/06/origin-of-covid-lab-leak-theory.html">laboratory in Wuhan</a> should have its own chapter. And if <a href="https://www.judicialwatch.org/press-releases/fauci-wuhan-826k/">this story</a> will be made into a movie, Brad Pitt should play Dr. Fauci... <br>
<br>
<small>[*] Much later another Nobel prize winner became famous for his predictions, which turned out to be mostly wrong. But he was not really a scientist.</small><br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com0tag:blogger.com,1999:blog-544041532485510036.post-73873301897162440682021-06-13T06:06:00.009-07:002021-06-13T06:35:52.006-07:00convivial links<a href="https://arxiv.org/abs/1505.05029">Herve Zwirn</a> proposes 'convivial solipsism' as a plausible interpretation of quantum theory. <br>
<small>I think he should have used LaTeX instead of an 80s version of WordPerfect to format his paper...</small><br>
<br>
<a href="https://www.youtube.com/watch?v=kC6j6dregRs">Michael Penn</a> looks at a geometric proof of <a href="https://en.wikipedia.org/wiki/Fermat%27s_little_theorem">Fermat's little theorem</a>.<br>
<small>He has lots of interesting stuff on YouTube...</small><br>
<br>
<a href="https://www.youtube.com/watch?v=cbI31x3FpS0">Remy</a> explains the current economy and financial markets. <br>
<small>Very trading ... such amaze ...</small><br>
<br>
<a href="http://blog.gorozen.com/blog/exploring-lithium-ion-electric-vehicles-carbon-footprint">Goehring & Rozencwajg</a> estimate the carbon footprint of electric vehicles.<br>
<small>Obviously, their results contradict the <a href="https://www.nature.com/articles/s41893-020-0488-7">Exeter, Nijmegen & Cambridge paper</a>...</small><br>
<br>
<a href="https://greenwald.substack.com/p/yet-another-media-tale-trump-tear">Glenn Greenwald</a> writes about yet another corporate media tale.<br>
<small>I have my own theory why US media evolved from news reporting to political propaganda...</small> <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com5tag:blogger.com,1999:blog-544041532485510036.post-4346778273521229842021-05-23T02:38:00.003-07:002021-05-23T02:55:43.076-07:00holesWe can collect light from a large but far away fusion reactor to generate electricity. <br>
A better way could be to use the heat from the nuclear reactor we inhabit. <br>
But in order to do this we would need to drill holes up to 10km deep through granite in many places
and this is a surprisingly difficult problem. <br>
Surprisingly, because we are able to dig tunnels through mountains and we can drill deep enough holes to produce oil and gas.<br>
However, existing rotary drilling technology is not sufficient to unlock geothermal energy in most places. <br>
<br>
A research project at the University of Leoben, Austria, investigates <a href="https://pure.unileoben.ac.at/portal/en/publications/rock-mechanical-investigations-related-to-the-development-of-an-alternative-drilling-technology(28ee3f09-7ff6-4b41-b9ca-62c217a80f10).html?customType=theses">an alternative drilling technology using water jets</a>, which looks promising. <br>
But perhaps it will take <a href="https://www.youtube.com/watch?v=tu-tzV0Mi_I">a billionaire and plasma jets</a> (YouTube, fwd to 43:30) to solve this problem: <a href="https://www.ipulse-group.com/about">link</a>.<br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com6tag:blogger.com,1999:blog-544041532485510036.post-8614153798307801262021-05-15T03:52:00.010-07:002021-05-16T03:50:06.697-07:00learning and understanding<a href="http://capitalistimperialistpig.blogspot.com/2021/05/herd-immunity.html">CIP</a> asked "from what books did you learn QM, QFT, and GR?" <br>
I guess it depends on your definition of "learning" ... <br>
<br>
I read several pop.sci. books as a kid, including Misner, Thorne & Wheeler 8-) <br>
So I had some idea what physics was about before I went to university. <br>
<br>
But I would say I learned relativity from the books of two Austrian physicists, Sexl & Urbantke. <br>
I learned quantum theory from the Berkeley lectures and Landau & Lifshitz. <br>
And I learned QFT from xeroxed lecture notes and Ryder. <br>
<br>
Of course there are many good books available now and some really good online lectures, e.g. <a href="https://www.youtube.com/watch?v=pyX8kQ-JzHI&list=PLQrxduI9Pds1fm91Dmn8x1lo-O_kpZGk8">Lenny Susskind</a>.<br>
<a href="https://www.amazon.com/General-Relativity-Robert-M-Wald/dp/0226870332">Wald</a>, <a href="https://www.amazon.com/Quantum-Field-Theory-Nutshell-nutshell/dp/0691140340">Zee</a> and <a href="https://www.amazon.com/First-Course-String-Theory-2nd/dp/0521880327">Zwiebach</a> are good books imho. <br>
<br>
But I should also mention that I learned a lot about quantum theory in a seminar with Anton Zeilinger, which included eye opening interference experiments with slow neutrons at a research reactor in Vienna. <br>
I think I really learned relativity during my master thesis, writing a program to numerically integrate the equations to simulate the gravitational collapse of a scalar field into a black hole. <br>
And I really learned something about QFT by writing programs to simulate lattice field theories; including <a href="http://wbmh42.000webhostapp.com/files/files.html">attempts to simulate quantum gravity</a>.
We did not really succeed, but I learned quite a lot along the way ... in some sense moving from <a href="https://www.amazon.com/Quantum-Field-Theory-Dover-Physics/dp/0486445682">Itzykson & Zuber</a> to <a href="https://www.amazon.com/Statistical-Field-Theory-Renormalization-Mathematical/dp/0521408059">Itzykson</a> & <a href="https://www.amazon.com/Statistical-Cambridge-Monographs-Mathematical-Physics/dp/0521408067">Drouffe</a>. <br>
<br>
Last but not least, I should mention that our best theories contain several unsolved mysteries: naked singularities, closed timelike loops, the 'interpretation problem' of quantum theory (*), Landau poles, the 'direction of time' etc. <br>
They are ultimately incomplete and even inconsistent and therefore one might say that nobody really understands them ... <br>
<br>
<br>
(*)<small> Physicists cannot agree if quantum theory describes one or many worlds, while I prefer <a href="https://www.scottaaronson.com/blog/?p=5359#comment-1881926">a zero worlds interpretation</a>. </small><br>
<br>Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com5tag:blogger.com,1999:blog-544041532485510036.post-79358852822856054132021-04-18T04:41:00.006-07:002021-04-27T02:29:07.880-07:00alien mathPerhaps we should think more about <a href="http://www.math.hawaii.edu/~jb/four.pdf">alien math</a> (pdf), since <i>they</i> seem to be everywhere now (see my <a href="https://wbmh.blogspot.com/2021/01/mostly-harmless.html">previous post</a>). <br>
<br>
Or perhaps we should just try to solve some weird math problems, like this one: <br>
"One day it started snowing in the morning at a heavy and steady rate. <br>
A snowplow started out at noon, going 2 miles in the first hour and 1 mile in the second hour." <br>
What time did it start snowing?" <br>
<br>
You should assume that the snowplow's speed is inversely proportional to the height of snow.<br>
<br>
You can find the solution <a href="https://www.youtube.com/watch?v=JKtooOjgINY">here</a> and I post this problem and link mostly for Lee,
who likes math puzzles.<br>
I think MindYourDecisions is a great source ... <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com3tag:blogger.com,1999:blog-544041532485510036.post-71851351148915478382021-01-10T04:29:00.005-08:002021-01-10T05:06:31.662-08:00mostly harmlessUnfortunately, free speech on US social media officially ended yesterday; <br>
the good people will no longer have to endure the opinions of those other 74 million. <br>
<nr>
Consequently, my own small contributions on US controlled websites shall remain mostly harmless ... <br>
<br>
------ <br>
<br>
Avi Loeb is publishing <a href="https://en.wikipedia.org/wiki/Extraterrestrial:_The_First_Sign_of_Intelligent_Life_Beyond_Earth">a book about Oumuamua</a>, arguing that it is the object of an alien civilization.<br>
Recently, SETI picked up <a href="https://www.smithsonianmag.com/smart-news/astronomers-discover-mysterious-radio-signal-proxima-centauri-180976602/">a mysterious signal from Proxima Centauri</a> and several <a href="https://en.wikipedia.org/wiki/List_of_works_similar_to_the_2020_Utah_monolith">strange monoliths</a> appeared in different places. <br>
Naturally, I wonder what to make of all those <a href="https://en.wikipedia.org/wiki/Pentagon_UFO_videos">reports about UFOs</a> and alien artifacts popping up now. <br>
<br>
Perhaps they just don't want to miss the series finale of <i>Earth, planet of the crazy apes</i> ... <br>
<br>
Elon Musk thinks that <a href="https://twitter.com/elonmusk/status/1347126794172948483">the most entertaining outcome is the most likely</a> - as seen from their perspective, not ours, unfortunately.<br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com14tag:blogger.com,1999:blog-544041532485510036.post-71893600718525417252020-11-08T03:56:00.004-08:002020-11-08T03:59:59.746-08:00four seasons<br>
<img src="https://1.bp.blogspot.com/-mqwDsCDssSI/X6fcNnYuygI/AAAAAAAAAw8/EDYtYTeaeyMgtTFMVYsWyR6_77OC7ZSewCNcBGAsYHQ/s0/maga.jpg"><br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.comtag:blogger.com,1999:blog-544041532485510036.post-13136804774075517382020-11-02T01:01:00.006-08:002020-11-02T01:07:10.547-08:00independenceScott writes about <a href="https://www.scottaaronson.com/blog/?p=4974">the Continuum Hypothesis</a> , a topic I find fascinating, although I never really understood it (I belong to his target audience of complete idiots).<br>
But he has a talent to explain difficult proofs in a way that makes me believe I understand them and, as I get older, this is all I really need. <br>
Of course, I had to ask <a href="https://www.scottaaronson.com/blog/?p=4974#comment-1863648">a silly question</a>, but he <a href="https://www.scottaaronson.com/blog/?p=4974#comment-1863717">did not really bite</a> ... <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com2tag:blogger.com,1999:blog-544041532485510036.post-31602564173194188102020-10-16T02:43:00.001-07:002020-10-16T02:56:14.599-07:00predictions ..." I will predict, though, that before December 31, 2020, fleets of driverless taxis will be on the road in more than ten cities." <br>
<a href="http://capitalistimperialistpig.blogspot.com/2018/12/auto-autos.html">CIP</a><br>
<br>
I was reminded of this prediction when Elon Musk announced recently for the n-th time that <a href="https://thenextweb.com/shift/2020/08/06/why-elon-musk-is-wrong-about-level-5-self-driving-cars-syndication/">very soon his cars will be fully autonomous</a>. <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com5tag:blogger.com,1999:blog-544041532485510036.post-87430739505107883382020-08-03T11:20:00.000-07:002020-08-12T03:48:33.945-07:00gone fishing<img border="0" src="https://3.bp.blogspot.com/-ZLIdL_NvNBo/XYkM0y5g60I/AAAAAAAAArc/xa8mU0VS_X8tY5rADKQgBXIJRYp_IfP9gCNcBGAsYHQ/s1600/gone_fishing.jpg" data-original-width="504" data-original-height="801"><br>
<br>
<small>Paul Klee: <a href="https://www.moma.org/collection/works/33587">Der Angler</a></small><br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.comtag:blogger.com,1999:blog-544041532485510036.post-69807583995357347242020-07-06T02:45:00.005-07:002020-07-06T02:54:37.911-07:00the fog and the princesRecently, I watched two documentaries that I found quite interesting.<br>
<br>
<a href="https://documentaryheaven.com/the-fog-of-war/">The Fog of War</a> tells the story of Robert McNamara, in particular his experience of the 'cold war' and the Vietnam war; I think every politician should be required to watch it.<br>
It provides several examples of smart men (and Robert McNamara was certainly very intelligent) doing really stupid things ... <br>
<br>
<a href="https://www.youtube.com/watch?v=5-IZZxyb1GI">Princes of the Yen</a> documents the actions of the Bank of Japan after WW2, until and after the bubble burst in 1990.<br> I always feel that I don't know enough about Asia and Japan in particular,
however, I disagree with the extrapolations at the end of the documentary; I do not understand central banks as omnipotent manipulators of the world economy.<br>
Perhaps another documentary should be made about the Federal Reserve, from Alan Greenspan to Jay Powell. <br>
I already have a title: "Clowns of the Dollar". <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com3tag:blogger.com,1999:blog-544041532485510036.post-77308505389496462382020-07-05T03:18:00.002-07:002020-07-05T05:43:54.716-07:00the one percentWe all know that the vast majority of the interweb is just garbage and the swamp continues to grow at an amazing speed.<br>
In fact the swamp animals <a href="https://slatestarcodex.com/2020/06/22/nyt-is-threatening-my-safety-by-revealing-my-real-name-so-i-am-deleting-the-blog/">work hard</a> to get rid of the valuable stuff ... <br>
But there is still the one percent of high quality and recently I found another piece of it: <br>
The lectures of Stanford professor Robert Sapolsky on <a href="https://www.youtube.com/watch?v=NNnIGh9g6fA&list=PL150326949691B199">the biology of human behavior</a>. <br>
I am surprised that we are still allowed to see it ... <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com10tag:blogger.com,1999:blog-544041532485510036.post-89154006438839224572019-11-06T04:18:00.001-08:002019-11-06T05:52:12.650-08:00My introduction to RIn previous blog posts I presented an introduction to R in eight steps: <br>
<br>
<a href="http://wbmh.blogspot.com/2019/10/my-introduction-to-r-step-1.html">step 1</a>: Installation of R and RStudio. <br>
<a href="http://wbmh.blogspot.com/2019/10/my-introduction-to-r-step-2.html">step 2</a>: Set working directory and load data.<br>
<a href="http://wbmh.blogspot.com/2019/10/my-introduction-to-r-step-3.html">step 3</a>: Variables and data types.<br>
<a href="http://wbmh.blogspot.com/2019/10/my-introduction-to-r-step-4.html">step 4</a>: Vector slices and linear regression.<br>
<a href="http://wbmh.blogspot.com/2019/11/my-introduction-to-r-step-5.html">step 5</a>: Vector arithmetic and data frames.<br>
<a href="http://wbmh.blogspot.com/2019/11/my-introduction-to-r-step-6.html">step 6</a>: for loops<br>
<a href="http://wbmh.blogspot.com/2019/11/my-introduction-to-r-step-7.html">step 7</a>: Define a procedure and use if ... else.<br>
<a href="http://wbmh.blogspot.com/2019/11/my-introduction-to-r-step-8.html">step 8</a>: Install packages and use external libraries.<br>
<br>
I called it "My introduction ..." because it emphasizes what I find important and interesting in R, rather than a tutorial of R as just another programming language. <br>
Perhaps R is an acquired taste, but it has become one of my preferred tools to understand the world ... <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com0tag:blogger.com,1999:blog-544041532485510036.post-17025555974517498322019-11-06T03:48:00.003-08:002019-11-06T03:53:14.737-08:00My introduction to R - step 8R is open source and many people have contributed and continue to contribute procedures, libraries and packages - and we have access to all of them. <br>
Perhaps we want to take a look at <a href="https://en.wikipedia.org/wiki/Kernel_regression">kernel regression</a>, one of many machine learning methods.<br>
Wikipedia even has <a href="https://en.wikipedia.org/wiki/Kernel_regression#Script_for_example">a script for us</a>. <br>
<br>
In order to try out the procedure npreg(), we install the package np and open its library of procedures <br>
install.packages("np") <br>
library("np") <br>
<br>
Instead of using the procedure install.packages() one can also select Tools > Install Packages ... from the RStudio menu. <br>
<br>
We then load the data we want to examine <br>
ryder = read.csv("R.csv",header=T) <br>
<br>
In this example, we try to explain the volume (in thousand shares) from the high - low range <br>
y = 0.0001*ryder$Volume <br>
x = ryder$High - ryder$Low <br>
<br>
Now we can build the non-parmateric model <br>
mdl = npreg( y ~ x ) <br>
and display it together with the data points <br>
plot( mdl ) <br>
points( x, y, col="blue" ) <br>
<br>
<img border="0" src="https://3.bp.blogspot.com/-cIaGmJwQJfI/XcKxu3R0snI/AAAAAAAAAuU/h8sv7Hb5IWUYNfIIjNRlF-HIO06boubXACNcBGAsYHQ/s1600/Rstd.png" data-original-width="1100" data-original-height="730"> <br>
<br>
exercise: Put the cursor next to the npreg procedure and hit F1 to get the help file. This tells us that npreg uses the parameter bws to set the bandwith (we just used a default). Use the procedure npregbw() to calculate the bandwith before calling npreg. <br>
Hint: There are examples at the end of the helpfile ... <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com0tag:blogger.com,1999:blog-544041532485510036.post-62000027096713473132019-11-05T04:09:00.000-08:002019-11-05T04:16:05.909-08:00My introduction to R - step 7We have used several procedures that come with the R base installation, e.g. plot, lm, read.csv, etc. <br>
But we can also define <a href="https://www.statmethods.net/management/userfunctions.html">our own procedures</a>. <br>
In the previous step we calculated the "exponential moving average" of a series of prices; perhaps we want to do this more than once. <br>
In this case it makes sense to define a procedure, which we will call MyEma <br>
MyEma = function( prc ){ <br>
L = length(prc) <br>
ema = numeric(L) <br>
ema[1] = prc[1] <br>
for( i in 2:L ){ <br>
ema[i] = 0.9*ema[i-1] + 0.1*ryder$Close[i] <br>
} <br>
return(ema) <br>
} <br>
<br>
We define our procedure MyEma to have 1 parameter, a vector of prices, then we perform the same calculation as in the previous step (you can actually copy and paste the code) and finally we return the exponential moving average vector as the result of our procedure. <br>
<br>
In the main body of our script we can then call the procedure <br>
ema = MyEma( ryder$Close ) <br>
with ryder$Close as the input. <br>
<br>
If all goes well the plot should be the same as in the previous step ... <br>
<br>
<img border="0" src="https://2.bp.blogspot.com/-PDKRayjOltw/XcFkBcpybsI/AAAAAAAAAuA/RGPPWv7Lb2I1IOHnHt3XG4MaC_934YbYACNcBGAsYHQ/s1600/Rstd1.png" data-original-width="1100" data-original-height="728"> <br>
<br>
There is only one issue: The loop assumes that there is more than one element in the vector prc and the whole procedure makes little sense if there are less than 3 elements in the prc vector. We should therefore check the length L and only do the loop IF L is larger than 2, otherwise just return the prc as it is. <br>
if( L > 2 ){ <br>
for-loop <br>
}
else{ <br>
return(prc) <br>
} <br>
<br>
This is depicted below. <br>
<br>
<img border="0" src="https://3.bp.blogspot.com/-z2dUn4_ea94/XcFlRDP_DTI/AAAAAAAAAuI/Bqg6MDabrQEuL7sRSnveQcmQWdxoI24TwCNcBGAsYHQ/s1600/Rstd2.png" data-original-width="1100" data-original-height="732"><br>
<br>
exercise: Use a 2nd parameter w in MyEma, so that <br>
MyEma = function( prc, w ){ <br>
and <br>
ema[i] = (1.0 - w)*ema[i-1] + w*ryder$Close[i] <br>
<br>
Call MyEma with different values of w and check how the plot changes <br>
MyEma( ryder$Close, 0.1) <br>
MyEma( ryder$Close, 0.05) <br>
MyEma( ryder$Close, 0.2) <br>
etc. <br>
<br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com0tag:blogger.com,1999:blog-544041532485510036.post-2559234925168655212019-11-04T03:27:00.000-08:002019-11-04T03:31:15.003-08:00My introduction to R - step 6Many investors prefer to sell stocks if they "enter into a down trend" - they use e.g. an exponential moving average and sell if the price falls below it. <br>
It is not clear if this actually improves the performance of a a stock portfolio, but perhaps investors sleep better using this approach ... <br>
<br>
There is no "exponential moving average" procedure in the R base package, but it can be easily calculated with a <a href="https://www.tutorialspoint.com/r/r_for_loop.htm">for-loop</a>. <br>
<br>
After loading the stock data file <br>
ryder = read.csv("R.csv",header=T) <br>
L = length(ryder$Close) <br>
<br>
we create the vector ema <br>
ema = numeric( L ) <br>
<br>
We set the first element of ema to the first close price <br>
ema[1] = ryder$Close[1] <br>
<br>
and then we calculate <br>
ema[2] = 0.9*ema[1] + 0.1*ryder$[2] <br>
ema[3] = 0.9*ema[2] + 0.1*ryder$[3] <br>
. <br>
. <br>
. <br>
in a loop: <br>
<br>
for( i in 2:L ){ <br>
ema[i] = 0.9*ema[i-1] + 0.1*ryder$Close[i] <br>
} <br>
<br>
Finally, we display the prices and ema <br>
plot( ryder$Close, type = "l", col = "blue" ) <br>
lines( ema, type = "l" , col = "red" ) <br>
<br>
<img border="0" src="https://4.bp.blogspot.com/-Q7UAQSw1Am0/XcAJSABxZuI/AAAAAAAAAt0/GZdZcg9rXG4C1urHJ7H4f2iujt5D9alaACNcBGAsYHQ/s1600/Rstd.png" data-original-width="1100" data-original-height="733"> <br>
<br>
At this point most tutorials would emphasize that R is an interpreted language and for-loops should be avoided at all costs. <br>
Indeed one should use vector operations whenever possible instead of the element-by-element processing in a for loop. <br>
However, microprocessors are so fast nowadays, that for-loops are problematic only for really large data sets imho. <br>
<br>
exercise: Repeat the calculation, but with the volume instead of the price. <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com0tag:blogger.com,1999:blog-544041532485510036.post-63384541540193698912019-11-01T03:47:00.001-07:002019-11-01T04:20:17.807-07:00My introduction to R - step 5An important feature of R is that one calculates with vectors and therefore can process large quantities of data in a single line. <br>
Let's take the data from previous steps <br>
ryder = read.csv("R.csv",header=T) <br>
and calculate the "trading range", normalized by the open, for every day <br>
tRng = ( ryder$High - ryder$Low )/ ryder$Open <br>
<br>
This generates the vector tRng , calculates the difference of high and low for every day, divided by the open and assigns the result to the elements of tRng, i.e. 251 * 2 calculations, all in one line. <br>
<br>
We can now add this vector to the data frame ryder <br>
ryder$TR = tRng <br>
<br>
Now let's calculate the dollar trading volume in thousands for each day and add it as a column <br>
ryder$dVol1000 = 0.001*ryder$Close * ryder$Volume <br>
<br>
We can take a look at the first entries of the data frame with the head() procedure <br>
head(ryder) <br>
but we would see the same thing in window 3 top right. <br>
<br>
If we want to store the expanded data frame in a file, we could do it as follows <br>
write.csv( ryder, "Rnew.csv", row.names=F, quote=F ) <br>
I set the parameters so that it has the exact same format as R.csv. <br>
You can get help with <br>
help("write.csv") <br>
<br>
The columns of ryder are: Date, Open, High, Low, Close, Adj.Close, Volume, ... <br>
and we can access each column by its name <br>
print( ryder$Close[3] ) <br>
But we can also access the elements of a data frame directly <br>
print( ryder[3,5] )<br>
The first index is the row and the second the column (Close is the 5-th column of ryder). <br>
<br>
We can also slice data frames <br>
df1 = ryder[100:200, ] <br>
head( df1 ) <br>
Notice that the blank entry, instead of an index, means all columns. <br>
<br>
df2 = ryder[ , 1:5] <br>
head( df2 ) <br>
The blank entry, instead of an index, means all rows. <br>
<br>
Until now, I have not mentioned the column Date and for a good reason - it is a bit of a mess. <br>
The read.csv procedure interprets it as a <a href="https://www.tutorialspoint.com/r/r_factors.htm">Factor</a> and not a date, although the entries are formatted so that R can interpret it as date. <br>
<br>
But we can fix that <br>
Dt = as.Date( ryder$Date ) <br>
ryder$Date = Dt <br>
help("as.Date") <br>
<br>
The as. family of conversion functions is quite useful in R. <br>
<br>
This allows us to slice the data frame ryder in yet another way ...<br>
r19 = ryder[ryder$Date > "2019-01-01",] <br>
head( r19 ) <br>
<br>
... and concludes this step of my introduction. <br>
<br>
exercise: Calculate the returns of ryder for each day, beginning with the 2nd day. <br>
The return on the 2nd day is ( ryder$Close[2] - ryder$Close[1] )/ryder$Close[1] , <br>
the return on the 3rd day is ( ryder$Close[3] - ryder$Close[2] )/ryder$Close[2] , <br>
etc.
Now calculate it in one line and assign the results to a vector Ret. <br>
hint: Use L = length(ryder$Close) in your calculation ... <br>
<br>
<img border="0" src="https://4.bp.blogspot.com/-yED8yhcg9Ds/XbwRiXs6ftI/AAAAAAAAAto/pXJi2BJDH6UReDCPWxnkV-UPGB-8rLvCACNcBGAsYHQ/s1600/Rstd.png" data-original-width="1100" data-original-height="730"><br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.comtag:blogger.com,1999:blog-544041532485510036.post-136521952105081262019-10-31T03:48:00.003-07:002019-10-31T04:00:52.383-07:00My introduction to R - step 4Linear regression is the oldest machine learning method. It is widely used and allows one to extrapolate from the known to the unknown. <br> Large fortunes have been made and lost with the help of linear regression models ...<br>
In the following we will calculate a linear model on a sample of stock prices and then compare it against stock prices "out of sample". <br>
<br>
If you start RStudio, it might show an R script with leftovers from the previous exercise - I suggest you create a new script (menu bar: File > New File > R Script). <br>
<br>
We read the R.csv file from step 2 with read.csv: <br>
ryder = read.csv("R.csv",header=T) <br>
and then store the length of the vector ryder$Close: <br>
L = length(ryder$Close). <br>
<br>
We calculate two variables we will later use for displays: <br>
maxP = max(ryder$Close) + 5.0 <br>
minP = min(ryder$Close) - 5.0 <br>
<br>
The file should contain more than 250 data points (one year of stock prices) and we use the first 200 days for <i>in sample</i> estimation. <br>
days = 1:200 <br>
prc = ryder$Close[days] <br>
<br>
Notice that ryder$Close is a vector and ryder$Close[1] is the first element we want and ryder$Close[200] the last of the in-sample period.
ryder$Close[days] is equivalent to ryder$Close[1:200] and therefore prc is a vector which stores the first 200 elements of ryder$Close. <br>
This <i>slicing</i> of vectors is quite often used and would work even if the elements of days would not be sequentially ordered. <br>
<br>
Now we can plot the prices as a function of each day: <br>
plot( days, prc, ylim = c(minP,maxP) ) <br>
<br>
We calculate the linear regression model with the lm() procedure: <br>
mdl = lm( prc ~ days) <br>
Notice the ~ used in the procedure call (which may or may not not be easy to find on a non-US keyboard). <br>
We can print a summary of the linear model with <br>
summary(mdl) <br>
and we get the two coefficients (intercept and slope) using coef(mdl), which returns a vector. <br>
Therefore we can calculate the linear model as <br>
lin = coef(mdl)[1] + coef(mdl)[2]*days <br>
<br>
and add the line to our plot with the lines() procedure: <br>
lines( days, lin, type="l", col="red") <br>
<br>
<img border="0" src="https://2.bp.blogspot.com/-K0Ruf2CXw2k/Xbq5KuymztI/AAAAAAAAAtQ/aGR0DSWtj4gUA-NB6N1__Sxq80dmQWlpACNcBGAsYHQ/s1600/Rstd.png" data-original-width="1000" data-original-height="633"><br>
<br>
You can either execute your script step by step with Ctrl-Enter or type the script first and then execute the whole thing by selecting from the menu: Code > Run Region > Run All <br>
<br>
Now we look at the out-of-sample data: <br>
days = 201:L <br>
prc = ryder$Close[days] <br>
and display it with<br>
plot( days, prc, ylim = c(minP,maxP) ) <br>
<br>
We calculate the out-of-sample model <br>
lin = coef(mdl)[1] + coef(mdl)[2]*days <br>
and add the line to the plot <br>
lines( days, lin, type="l", col="red") <br>
<br>
<img border="0" src="https://1.bp.blogspot.com/-f-6SG9C0Des/Xbq6_aSymSI/AAAAAAAAAtc/Zm13cf0eKg8Opj1Z3PE7zSM6lth2ZJUWQCNcBGAsYHQ/s1600/Rstd2.png" data-original-width="1000" data-original-height="632"><br>
<br>
We could now calculate the out-of-sample error (it is quite obvious that the error exceeds the variance of the data in this example 8-) and perhaps repeat the procedure for many different stocks and time periods to check if the linear model has any useful predictive value. <br>
However, this concludes step 4 of my introduction <br>
<br>
exercise: Repeat this regression exercise, but use the Volume instead of the Close ... <br>
<br>
Wolfganghttp://www.blogger.com/profile/07086991199438418163noreply@blogger.com0