Shylock appears in only five scenes in the play yet his presence is felt throughout the play from the Rialto to Belmont. It must be understand that Shylock is a Jew living in a Christian society. Money lending was one of the few professions he could practice. As a Jew, he was a second class citizen.
Shylock first appears in Act I, scene 3 because Antonio needs to borrow 3, 000 ducets, an extremely large sum of money. Notice he doesn't speak verse until Antonio arrives. He is talking down to Bassanio. In this scene, Shylock has the upper hand. It would appear that despite the attitude of Antonio and Bassanio of Shylock being a second class citizen, Shylock views himself above his enemies.
He has been a victim of prejudice his entire life and finds it ironic that Antonio who has spit on him and kicked him and also called him names, needs his help. He seems to enjoy toying with the two men he holds in contempt.
Perhaps the best understanding of how he views himself can be found in Act III, scene 1 when he encounters Salerio and Solanio who goad him and he responds with his justification of revenge. In the speech, he compares Jews and Christians and finds that they are the same. In other words, he tells the two men that he is their equal.
The Venetian society believed that all Jews were unbelievers and therefore condemned. This justified their treatment of them. It was OK to hit or spit at a Jew because, well, they weren't Christians.
They also believed it was their duty to correct this situation so in Act IV it was perfectly logical for the Christian court to force Shylock to give up his identity and become a Christian. They were saving the man's soul, for heaven's sake.
I'm not sure Shylock would agree.
This is a great question. You are right in identifying a disparity between how Shylock views himself and how others view him. For me, you need to analyse Act I scene 3 to be able to grasp this difference. This is the scene where Bassanio and then Antonio go to Shylock to negotiate the terms of the loan, and Shylock makes clear in an aside his hatred of Antonio, but more than that: he establishes his position as a victimised and wronged Jew who has suffered racial prejudice from people such as Antonio for centuries:
If I can catch him once upon the hip,
I will feed fat the ancient grudge I bear him.
He hates our sacred nation, and he rails,
Even there where merchants most do congregate,
One me, my bragains, and my well-won thrift,
Which he calls interest. Cursed be my tribe
If I forgive him!
Shylock here pledges himself to revenge against Antonio, choosing him as a representative of the wrongs that he and his "tribe" have suffered. He appoints himself as the Jew responsible for gaining this revenge.
Note, however, that to Antonio, Shylock is a character akin to the devil. Following Shylock's allusion to the trick of Jacob in taking the good herd from his father in law Laban, Antonio responds:
Mark you this, Bassanio,
The devil can cite Scripture for his purpose.
An evil soul producing holy witness
Is like a villain with a smiling cheek,
A goodly apple rotten at the ehart.
O, what a goodly outside falsehood hath!
To Antonio, therefore, as to other characters, Shylock represents the worst of Jewish miserliness and acquisitiveness. He is a "Devil" in that he twists scripture to his purpose and is a hypocrite as he presents one face only to be a villain underneath.
I agree that my answer is inadequate. The question, how does Shylock view himself is good because he faces two difficult problems. One is how to respond to Antonio's offences and the other is Jessica's elopement. As others have noted, he also must deal with the historical context(alluded to in the speeches "Signor Antonio, many a time and oft........"(1.3.103-125) and "tell not me of mercy......"(3.3.1-17). Others also have noted his reference to one Leah, who is thought to have been his wife. His "no ill luck stirring but what lights o' my shoulders, no sighs but o' my breathing, no tears but o' my shedding"(3.1.89-91), is noted in an 1879 theatre review included in the SIGNET edition as expressing his grief. It is then reasonable to note that throughout the play one finds linguistic connections to ROMEO AND JULIET. Therefore, one of the "passions"(3.1.57) affecting Shylock in the court scene is similar to Romeo's in Act 5 of ROM. As I am an amateur, you might ask others if there is a usage error in the structure of your question.
Before Shylock speaks(1.3) there is talk of Antonio's "sadness." Antonio has been pegged "a puzzle at the center of the play"(see Norrie Epstein's book). The fairy tale element(see Professor Bevington's intro) is then presented allowing one to say that in the play we find various proverbial stuff and find Shylock and Antonio are angry at each other and the nice lady tells them to straighten up and fly right. One brief answer to the question is also in Act 1, scene 3: Shylock's views are "in supposition"(1.3.17). When he says " and it shall go hard but I will better the instruction"(3.1.68-9), does "better" mean improve or simply outdo? There is also obscurity regarding how others view Shylock. In the court scene, Gratianio says, "O, be thou damned, inexecrable dog"(4.1.127). Some editors have substituted inexorable(as in ROM5.3.38) for inexecrable. The obscurity is intended by the author, I would argue, given Bassanio's "Graziano speaks an infinite deal of nothing"(1.1.114). The above are facilitated, in part, by Portia's "Of a strange nature is the suit you follow"(4.1.174).